Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8287415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:02:03+00:00 2026-06-08T12:02:03+00:00

I have a problem with the Core Data and NSManagedObject class. I have a

  • 0

I have a problem with the Core Data and NSManagedObject class. I have a data model with an entity “UserProfile” which contains several attributes including “userId“, “username” and “clientId” which are essential. All these three attributes are marked as “String” in the Core Data Model.

The UserProfile source contains the following:

// UserProfile.h
#import <Foundation/Foundation.h>

@interface UserProfile : NSManagedObject

@property (nonatomic, retain) NSString* userId;
@property (nonatomic, retain) NSString* clientId;
@property (nonatomic, retain) NSString* userName;

// simple routine to display essential information about the user in the user table row
- (NSString*) obtainUserInfo;


// UserProfile.m
@implementation UserProfile

@dynamic userId;
@dynamic userName;
@dynamic clientId;

- (NSString*) obtainUserInfo
{
    return [NSString stringWithFormat:@"%@ - %@", [self valueForKey:@"clientId"], [self valueForKey:@"userName"]];
}

I create a new instance of the UserProfile class when the user has filled a form with some text fields and push a submit button. The relevant code chunk in the callback method is the following:

Q3AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];

NSManagedObjectContext *context = [appDelegate managedObjectContext];

NSEntityDescription *desc = [NSEntityDescription entityForName:@"UserProfile" inManagedObjectContext:context];

// this line creates the managed object instance and stores it!
UserProfile *newProfile = [[UserProfile alloc]initWithEntity:desc insertIntoManagedObjectContext:context];

// editing properties now causes the object's state to switch to "isChanged". Changes only persist if they're explicitely saved
[newProfile setUserId: [UUIDCreater generateUUID]];
[newProfile setClientId: clientField.text];
[newProfile setUserName: userNameField.text];

NSError *error = nil;
[context save:&error];

if (!error)
{
    // now send the result data to the other controller (via the delegate object)
    [delegate newProfileCreated];


    // dismiss this view
    [self dismissModalViewControllerAnimated:YES];
}
else 
{

    NSLog(@"Error: %@", error);

}

Next, a table view controller extracts all UserProfiles from the Core Data storage and displays them using prototype cells.

Okay, this all works so far, but my problem begins in this code of the UserProfilesTable class which is the ViewController of the UserProfile table view.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"userProfileEntry";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


// Configure the cell...
UserProfile *obj = [_userProfileList objectAtIndex:indexPath.row];
NSLog(@"ClientId: %@", [obj valueForKey:@"clientId"]);
NSLog(@"UserName: %@", [obj valueForKey:@"userName"]);

// !!CRASH!!
NSLog(@"From Method: %@", [obj obtainUserInfo]);

cell.textLabel.text = [NSString stringWithFormat:@"%@ - %@", [obj valueForKey:@"clientId"], [obj valueForKey:@"userName"]];   
return cell;
}

The first two NSLogs print the correct values that I have just entered in the form to create the new user profile (and hence, the command below the crash also works as expected).
So.. with basic KVC I get the values for clientId and userName out of the UserProfile instance, but why does the app crash with an…

NSInvalidArgumentException (reason: -[NSManagedObject obtainUserInfo]: unrecognized selector sent to instance 0x6c40b90) [0x6c40b90 in this case is my UserProfile instance]

…if i try to access the method from the UserProfile class which does pretty much the same thing, just encapsulated into a separate method to improve changeability and stuff?

It seems that just because i subclassed NSManagedObject it won’t let me access my private class methods anymore. I set a breakpoint at the obtainUserInfo method and it isn’t fired which means to me that the app doesn’t even enter the method.

I found another thread which is basically the same problem as this, but the threadstarter answered it on his own and solved it by recreating the core data entity. I did the same and it didn’t solve my problem.

I’m running out of hints, so any suggestion is appreciated.

Thanks in advance.

EDIT: Fixed. Forgot to assign the class name of my UserProfile class to the Core Data Entity in the Data Model Inspector of XCode. Thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:02:07+00:00Added an answer on June 8, 2026 at 12:02 pm

    reason: -[NSManagedObject obtainUserInfo]: unrecognized selector sent to instance 0x6c40b90

    This message means that the object that is receiving (and failing to deal with) the obtainUserInfo message is an instance of NSManagedObject.

    [0x6c40b90 in this case is my UserProfile instance]

    No it isn’t. It is an instance of your UserProfile entity, but it is still of the NSManagedObject class. The basic properties being accessed by valueForKey: will still work in this case.

    This probably means that your data model doesn’t have a specific managed object subclass specified for the UserProfile entity, so new instances are being returned as NSManagedObjects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem I cannot solve with a Core Data entity. In my
I have a bizarre problem with a 'double' property in Core Data. I have
I am having a Core Data problem with NSFetchedResultsController . I have a one
I have a little problem, probably easy for you. Im using Core Data. I
I think I have a problem, maybe linked to a retain cycle in Core-Data.
My main problem is storing the data which is not supported by Core Data.
My problem is similar to: Problem creating NSManagedObject derived class I have setup a
So I'm fairly new to Core Data and KVO, but I have an NSManagedObject
I'm using Core data on my app ok, i have a problem when saving
I have a strange problem in my Core Data app. I have three entities

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.