static0886
static0886

Reputation: 784

Property not found on object of type

I have a simple question:

I have a NSManagedObject subclass that I've been using for some time and it was working perfectly fine. Today I added a new property to it with the corresponding iVar. The property is a simple (nonatomic,retain) NSString *. And as normal i added @synthesize to the property to generate setter and getter functions. However, there is no way i can use the newly defined property!!! I keep getting "property not found on object of type" error and my build fails.

Here are a few chunks of code that will clear things out:


    //import the core data header first CoreData/CoreData.h

    @interface Contact :  NSManagedObject

    {
       NSString *contactID;
       NSString *firstName;
       NSString *myDevMod;
    }

    @property (nonatomic,retain) NSString *contactID;
    @property (nonatomic,retain) NSString *firstName;
    @property (nonatomic,retain) NSString *myDevMod;

    @end

and the corresponding .m implementation:

    #import "Contact.h"

    @implementation Contact 

    @synthesize contactID, firstName, myDevMod;

and the code that uses the Contact class:

    #import "Contact.h" //at the start

    Contact *aContact = [[Contact alloc] init];
    aContact.contactID = someId; //works perfectly fine
    aContact.firstName = someName; //works perfectly fine
    aContact.myDevMod = @""; //THIS IS WHERE THE ERROR OCCURS!!
    [aContact doSomethingHere];
    [aContact release];

What do you think could be the error??

Thanks in advance for your support.

Upvotes: 1

Views: 7031

Answers (3)

Geert Jadoul
Geert Jadoul

Reputation: 1

My experience is that it isn't the model or the objects that need to be recreated. Most of the time you can recreate the file you are working in. Make a new NSView of what every .h and .m file and copy the info over to the new file, and it will work.

Upvotes: 0

rockstarberlin
rockstarberlin

Reputation: 1853

I had exact the same problem last night. It took me about 5 hours to fix that. My first attempts were to create the model classes again with menue Editor -> Create NSManagedObject Subclass...

But that didn´t help. Even if i had deleted the classes beforehand Xcode did not recognize the properties. I´ve deleted the model as well and rebuild it with same name. And created the NSManagedObject Subclasses again. Didn't help. Then i´ve deleted the model and the MOS again and build it up from scratch! But with different names! Took me again a long time to change my code but after that everthing seemed to be normal. Now i can add, change and delete attributes in the model and the properties NSManagedObject Subclasses and Xcode recognizes them again.

But boy, it almost drove me nuts!!! And i still don't know what happend!

Upvotes: 0

ader
ader

Reputation: 5393

Weirdly the site won't let me add a comment so :

comment: Sounds odd. First thing I'd try is removing the @property lines and @synthesize line - so the getters and setters are created automagically. Also try: aContact.myDevMod = someName; to see if that actually works - might shed some light.

Upvotes: 0

Related Questions