Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

thedon1

macrumors 6502a
Original poster
Jun 26, 2010
529
73
I'm following a tutorial, created a new iPhone project, then added a new Cocoa touch Class to the project. It's a subclass of NSObject.

In the header, i type the following:

Code:
#import <Foundation/Foundation.h>
@interface BNRLine : NSObject

@property (nonatomic) CGPoint begin;

And i get the error, "Unknown type name CGPoint"

It's very strange considering foundation has been imported, I have no idea why this is happening. I'm using Xcode 6.01.

Is there something really stupid i'm overlooking?

----------

OK looks like it's because ei haven't import UIKit but I never had to do this before. Has a default setting changed in 6.01?
 
Well, if importing UIKit fixes this then generating a class that doesn't have the import for UIKit won't work. You probably need the UIKit import and not the Foundation import.

I don't believe anything changed regarding this.

Mark this as resolved if it is.
 
Well, if importing UIKit fixes this then generating a class that doesn't have the import for UIKit won't work. You probably need the UIKit import and not the Foundation import.

I don't believe anything changed regarding this.

Mark this as resolved if it is.

As I vaguely recall, Xcode 6's project templates have a precompiled header (pch) that DOESN'T import UIKit.h. In earlier Xcode versions, the pch DID import UIKit. I think I read this in a thread in this forum, but I can't find it now. So the OP should look in the pch (if there is one) and see what's there. I don't know if this change in behavior is an intentional feature change or a bug.


To the OP:
You should use the exact version of Xcode called for by whatever tutorial you're following. If it says Xcode 5, use that. There is no guarantee that Xcode will stay the same over time and versions, and tutorials (especially for complete beginners) often have steps with version-specific instructions.

Beginners aren't expected to understand Xcode or its principles well enough to extrapolate for Xcode's changes. Thus, if you're using a different major Xcode version than what the tutorial is written for, you shouldn't expect things to work. They might work, but they might not.

Also, it helps us help you (or anyone else) when you point to the specific tutorial you're using (post the exact URL). That way we can look at it and see if what it says is correct for Xcode 6. Without knowing which tutorial you're using, no one knows how wrong or right the tutorial is.
 
CGPoint, and other CG types, are available from the CoreGraphics framework. It is an independent framework from UIKit, but generally you can't draw anything to the screen without setting up a CoreGraphics context via UIKit.
 
Hmmm, new projects in Xcode 6.x seem to not get a pch file at all. New classes that derive from UIKit classes get an import for UIKit in the header file but new classes that derive from NSObject get an import for Foundation.

So I guess that is what changed: No pch file.
 
It's likely that Apple wants people to use modules instead of prefix headers.
I have the problem on Xcode 8.2 beta. I am sharing a file of iPhone app to WatchOS app, then it shows that "Unresolved type 'CGPoint'."

So I don't need to import UIKit (or CoreGraphics) on the iPhone app, but I need to import it on the WatchOS app. Weird.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.