Unknown type name CGPoint?

Discussion in 'iOS Programming' started by thedon1, Oct 12, 2014.

  1. thedon1 macrumors 6502

    Joined:
    Jun 26, 2010
    #1
    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?
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    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.
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
    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.
     
  4. Madd the Sane macrumors 6502

    Madd the Sane

    Joined:
    Nov 8, 2010
    Location:
    Utah
    #4
    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.
     
  5. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    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.
     
  6. Madd the Sane macrumors 6502

    Madd the Sane

    Joined:
    Nov 8, 2010
    Location:
    Utah
    #6
    It's likely that Apple wants people to use modules instead of prefix headers.
     
  7. allenlinli macrumors newbie

    allenlinli

    Joined:
    Nov 8, 2016
    #7
    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.
     

Share This Page