XCode 4.2 NSManagedObject context build failed
Asked Answered
J

3

10

I created an UserModel.xcdatamodeld with one Entry: UserBase, and I added an attribute which name is UserID and type is Integer 32.

After that, I create classes for it with file->new file->NSManagedOBject subclass, which creates UserBase.h and .m automatically.

In my controller imported the UserBase.h file, and create a property:

NSManagedObjectContext *userBaseObjectContext;

with

@property (nonatomic, retain) NSManagedObjectContext *userBaseObjectContext;

In mycontroller.m file synthetized the userBaseObjectContext property and in DidLoad function I tried this:

UserBase *userObject=(UserBase *)[NSEntityDescription insertNewObjectForEntityForName:@"UserBase" inManagedObjectContext:userBaseObjectContext];
        [userObject setUserID:[NSNumber numberWithInt:42]];
        NSError *error;
        if(![userBaseObjectContext save:&error])
        {
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Application error" message:@"error" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil,nil];
            [alert show];
            [alert release];
        }
        else
            NSLog(@"not working...");

When I try to build my project, I got this error:

Undefined symbols for architecture i386:
 "_OBJC_CLASS_$_NSEntityDescription", referenced from:
  objc-class-ref in LoginController.o
 "_OBJC_METACLASS_$_NSManagedObject", referenced from:
  _OBJC_METACLASS_$_UserBase in UserBase.o
 "_OBJC_CLASS_$_NSManagedObject", referenced from:
  _OBJC_CLASS_$_UserBase in UserBase.o
 ld: symbol(s) not found for architecture i386
 clang: error: linker command failed with exit code 1 (use -v to see invocation)

What is that means?

I followed this tutorial: http://mobile.tutsplus.com/tutorials/iphone/iphone-core-data/

Jibheaded answered 2/12, 2011 at 16:28 Comment(1)
Try adding the CoreData.framework.Fatidic
P
20

Undefined symbols usually mean that some Framework is missing. Frameworks are libraries of pre-compiled classes you can use on your App.

To add a framework on XCode 4:

  1. Click on your Project's root (the item at the top left corner with the Blueprint icon).
  2. Click on your Target (Usually the same App name with an the "A icon made of pencils" at the left).
  3. Click on the "Summary" tab at the top, then scroll down... collapse the dividers and under "iPad Deployment Info" you will find the "Linked Frameworks and Libraries" section (See Figure 1 below).
  4. Click the "+" button at the bottom of that list.
  5. A popup will ask you to choose a Framework, search for it and when you have selected it, click Add.

And, that's it! Classes contained in that Framework will be available on your code as long you do the correct #import.

Figure 1:

enter image description here

To maintain your project ordered, I'll suggest to drag the newly added framework to the Group "Frameworks".

Papillon answered 7/3, 2012 at 0:25 Comment(1)
Also... add #import <CoreData/CoreData.h> in your "pch" fileAlti
T
3

If you imported the alert file into your project, make sure the tick box ticked on the Target Membership ! I had the same problem and after I ticked the box and the error disappeared !

Titanite answered 11/10, 2012 at 23:24 Comment(0)
K
0

Try to delete your NSManagedObject Class from project and generate it again. It helped me;)

Kylie answered 9/9, 2014 at 8:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.