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

  • SEARCH
  • Home
  • 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 9237815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:37:12+00:00 2026-06-18T07:37:12+00:00

I am having troubles with the relationship I have setup in CoreData. Its one

  • 0

I am having troubles with the relationship I have setup in CoreData. Its one to many, a Customer can have many Contact, these contacts are from address book.

My model it looks like this:

Customer <---->> Contact
Contact  <-----> Customer

Contact.h

@class Customer;

@interface Contact : NSManagedObject

@property (nonatomic, retain) id addressBookId;
@property (nonatomic, retain) Customer *customer;

@end

Customer.h

@class Contact;

@interface Customer : NSManagedObject

@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSSet *contact;

@end

@interface Customer (CoreDataGeneratedAccessors)

- (void)addContactObject:(Contact *)value;
- (void)removeContactObject:(Contact *)value;
- (void)addContact:(NSSet *)values;
- (void)removeContact:(NSSet *)values;

@end

And trying save with:

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
Customer *customer = (Customer *)[NSEntityDescription insertNewObjectForEntityForName:@"Customer" inManagedObjectContext:context];

[customer setValue:name forKey:@"name"];

for (id contact in contacts) {
    ABRecordRef ref = (__bridge ABRecordRef)(contact);
    Contact *contact = [NSEntityDescription insertNewObjectForEntityForName:@"Contact" inManagedObjectContext:context];

    [contact setValue:(__bridge id)(ref) forKey:@"addressBookId"];
    [customer addContactObject:contact];
}

NSError *error;

if ([context save:&error]) { // <----------- ERROR
    // ...
}

With my code, I have this error:

-[__NSCFType encodeWithCoder:]: unrecognized selector sent to instance 0x9c840c0
*** -[NSKeyedArchiver dealloc]: warning: NSKeyedArchiver deallocated without having had -finishEncoding called on it.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType encodeWithCoder:]: unrecognized selector sent to instance 0x9c840c0'

Any suggestions would be appreciated.

  • 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-18T07:37:13+00:00Added an answer on June 18, 2026 at 7:37 am

    The problem is that addressBookId is (as you mentioned in a comment) defined as a transformable attribute on the Contact entity. However (as you also mentioned in a comment) you don’t have any custom code to actually transform an ABRecordRef into something that Core Data knows how to store. With no custom transformer, Core Data is going to try and transform the value by calling encodeWithCoder: on the value. But ABRecordRef doesn’t conform to NSCoding, so this fails and your app crashes.

    If you want to store the ABRecordRef in Core Data, you’ll need to create an NSValueTransformer subclass and configure that in your data model. Your transformer would need to convert ABRecordRef into one of the types Core Data knows. I haven’t worked with the address book API enough to advise on the details of this, but Apple documents NSValueTransformer pretty well.

    The fact that it’s a one-to-many relationship is irrelevant; the problem is that ABRecordRef can’t go into your data store without some transformation.

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

Sidebar

Related Questions

im having troubles with adding a class to the last option from foreach, its
I'm having a little trouble grasping CoreData relationships, i'm note sure which relationship type
I am having troubles in OpenGL due to the fact that textures have to
I am building a core data iphone app, and having trouble with retrieving one-many
I'm having trouble saving a many-to-many relationship with nhibernate. I searched and looked at
I am having trouble with my first join-table for a many to many relationship.
I'm having some troubles getting a set of Entities setup to work correctly. I'm
I'm having trouble wrapping my head around joining tables. I have a one_to_many relationship
I am having trouble figuring one of several error messages that seem to have
I am having trouble with a one-to-one bi-directional relationship I am trying to create

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.