iOS Unknown type name CGPoint?

thedon1

macrumors 6502
Original poster
Jun 26, 2010
482
52
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?
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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.
 

chown33

Moderator
Staff member
Aug 9, 2009
8,817
5,224
vertical
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.
 

Madd the Sane

macrumors 6502a
Nov 8, 2010
510
42
Utah
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.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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.
 

allenlinli

macrumors newbie
Nov 8, 2016
1
0
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.