Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Critical unexplainable problem with NSObject

JohanovskiJohanovski Posts: 343Registered Users @ @
edited May 2013 in iOS SDK Development
Hi there!

I'm suffering the most painful problem I've ever suffered with iOS programming. I've been developing a Cocos2D Chipmunk based game for some days and everything used to work fine. However, for no apparent reason, the problem suddenly stopped compiling and gave a huge pack of strange errors saying that it cannot find the "NSObject" class, which is the superclass of one of my custom classes. After this error, the compiler even complains about things like CGPoints, CGSizes, BOOL, etc. It is like XCode suddenly forgotten the WHOLE iOS basic classes. These are the strangest errors I have when trying to compile:

Entitat.h:11:22: Cannot find interface declaration for 'NSObject', superclass of 'Entitat'
Entitat.h:15:5: Unknown type name 'CGPoint'
Entitat.h:16:5: Unknown type name 'CGSize'
Entitat.h:21:40: Expected a type // This one appears on each method in the .h file
(...)
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
Here are the first few lines of my "Entitat.h" file:

#import <Foundation/Foundation.h>

@interface Entitat : NSObject                 // Cannot find interface declaration for 'NSObject', bla bla bla
{
    int idEntity;
    
    CGPoint position;                              // Unknown type name 'CGPoint'
    CGSize size;                                      // Unknown type name 'CGSize'
    
    BOOL active;                                      // Unknown type name 'BOOL'
}

-(id)initEntityWithId:(int)i Position:(CGPoint)pos Size:(CGSize)s Active:(BOOL)b;     // Expected a type

// Setters
-(void)setPosition:(CGPoint)p;                               // Expected a type
-(void)setActive:(BOOL)a;                                      // Expected a type
(...)

// And the same 'expected a type error' for every other method
What on Earth can be happening?? I used to run the project without ANY problem, and the class "Entitat" is the first class I created, from which other classes inherit. I've tried removing and deleting the last class I created, I've tried making a new project, copying the code for the general classes and importing my custom ones, I've tried deleting the app from the simulator, cleaning and rebuilding the project a thousand times, commenting the 'Foundation' and 'UIKit' imports from the 'Prefix.pch' and from the 'Entitat.h', etc... However, nothing seems to change this problem's behavior: everything I do drives to the same weird 'cannot find NSObject' problem, which I'm sure it drives to the others...

Any idea on what can be happening? I'm REALLY stuck with this, as I'm completely unable to do ANYTHING with to project as I can't even compile it... It is weird how this problem appeared like 5 days after using the "Entitat" class with any problem of any kind... Any help will be appreciated!

Thanks in advance for your time and effort!

Replies

  • Duncan CDuncan C Posts: 9,114Tutorial Authors, Registered Users @ @ @ @ @ @ @
    I sometimes accidentally type a bad character as the first character in one of my .h files and all hell breaks loose with the compiler.

    I suggest looking at the first few lines of ALL your source files, looking for spurious characters.
    Regards,
    Duncan C
    WareTo

    widehead.gif
    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
  • Duncan CDuncan C Posts: 9,114Tutorial Authors, Registered Users @ @ @ @ @ @ @
    In addition to checking for spurious characters in your files,

    try changing your import of foundation to:
    #import <UIKit/UIKit.h>
    
    That should include everything you need.
    Regards,
    Duncan C
    WareTo

    widehead.gif
    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
  • JohanovskiJohanovski Posts: 343Registered Users @ @
    Hi there,

    Thanks for your responses, but nothing seems to solve the problem... I tried searching every file for weird characters at the beginning, but I'm unable to find any of them. Also, I've replace the "Foundation" import with the "UIKit", but the problem is still the same... I'm not using any version control (though I know I should), but I've tried removing the last class I've created (and of course commenting every piece of code that interacts with this new class), but the problem persists... However, I don't think it has anything to do with my last own-made class, because when the app chocked horribly I was already working with this class for a while, and I wasn't doing anything weird with imports or new classes...

    It seems as if the project aren't correctly linking the system libraries (like "Foundation" or "UIKit"), because when I completely remove anything dealing with my "Entitat" class, which is the one that seems to show most of the errors, it is the "CFArray" class which collapses with a huge pack of errors... And yes, the "CFArray" class isn't even an own-made classe (I don't even know where it comes from)! I think "CFArray" belongs to the "CoreFoundation" package or something like this, so I think it's one of the classes coming from the imports... The errors shown in this class relate mainly about not recognizing "system commands", for example:
    
    /*	CFArray.h
    	Copyright (c) 1998-2012, Apple Inc. All rights reserved.
    */
    
    #if !defined(__COREFOUNDATION_CFARRAY__)
    #define __COREFOUNDATION_CFARRAY__ 1
    
    #include <CoreFoundation/CFBase.h>
    
    CF_IMPLICIT_BRIDGING_ENABLED     /////// Unknown type name 'CF_IMPLICIT_BRIDGING_ENABLED'
    CF_EXTERN_C_BEGIN                        /////// Expected ';' after top level declarator
    
    (...)
    
    typedef const void *	(*CFArrayRetainCallBack)(CFAllocatorRef allocator, const void *value);  // Unknown type name 'CFAllocatorRef'
    typedef void		(*CFArrayReleaseCallBack)(CFAllocatorRef allocator, const void *value);  // Unknown type name 'CFAllocatorRef'
    typedef CFStringRef	(*CFArrayCopyDescriptionCallBack)(const void *value);  // Function cannot return function type 'int (const void *)'
    
    (...)
    
    As you can see, aside from the fact that "CFArray" isn't even mine and that I've never modified it, it seems that anything related to the imported packages cannot be found or isn't correctly imported, which drives to the impossibility of recognizing the "NSObject" as the superclass of my own-made "Entitat" class, or recognizing data types like CGPoint, BOOL or any other "Objective-C"-made class'...

    Do you know what can be happening? I've searched for cycling imports but I didn't find anything that seemed to be causing the problem... I've even created a blank project and imported my own-made classes, but once I have imported it all, it drives to the same error, so I'm sure it should be something related to them in any way... However, the fact that I was working with no now classes when everything exploded makes the whole thing a mystery... Any clue?

    Thanks in advance for your time and effort! :)
  • JohanovskiJohanovski Posts: 343Registered Users @ @
    Well, seems that the problem is *ehem* "solved"... I tried creating a new project and copying each one of my own-made classes except the last one I created: the project compiled without any problem. Then, I created a new classes (which is meant to be my last own-made class) with a different class' name and I copied the whole class's code in it. Then, I changed the class' references in the other files, and: TA-DA! The project compiles and works as fine as it did the instant before choking! I don't even know what crashed the project, but I suppose there are two possibilities:

    a) Something internal that has nothing to do with me crashed.
    b) My last own-made class' name was conflicting with some of the Apple's imports classes. However, removing this last class might have resolved the error, and it didn't, so it sounds weird... Also, a class names "Creature" isn't likely to be found in the "Foundation" imports, so...

    Well, everything is a mystery! Luckily, I've managed to get my project back to life (though I didn't even know why), and now I can continue working with it (typing the keyboard with a single hand, as I keep the other's fingers crossed to prevent the same error from happening again)!

    Thanks both for your help! :)
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,690Tutorial Authors, Registered Users @ @ @ @ @ @ @ @

    b) My last own-made class' name was conflicting with some of the Apple's imports classes. However, removing this last class might have resolved the error, and it didn't, so it sounds weird... Also, a class names "Creature" isn't likely to be found in the "Foundation" imports, so...

    You should prefix class names to avoid this possibility. For example, if this was my class, I would use BTIEntitat. Pick three letters that you like, and put them in front of all of your class names.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | SlickShopper 2 | Leave a PayPal donation
  • JohanovskiJohanovski Posts: 343Registered Users @ @
    Thanks for the advice, I think it's a great way for preventing possible conflicting class' names... I'll keep it in mind! ;)
Sign In or Register to comment.