I am trying to use an Undefined attribute that is also Transient. The attribute is of type ABRecordRef (which isn’t even an object in Objective-C), and I can get the object by using the ABRecordID, which is an int32 that I persist in my model.
I made the getter pretty easily:
- (ABRecordRef) abRecordPerson
{
ABAddressBookRef book = ABAddressBookCreate();
ABRecordRef record = ABAddressBookGetPersonWithRecordID(book, [self.abGlobalID intValue]);
return record;
}
This works fine, till I try to save a new object:
Person *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
newManagedObject.abGlobalID = [NSNumber numberWithInt: recordID];
//newManagedObject.abRecordPerson = person;
I get a crash whether I have the last line commented out or not. If it’s commented out, it gives me this error:
Unresolved error Error
Domain=NSCocoaErrorDomain Code=1570
“The operation couldn’t be completed.
(Cocoa error 1570.)”
UserInfo=0xe0138c0
{NSValidationErrorObject= (entity: Person; id:
0xc611e10; data: {
abGlobalID = 6;
abRecordPerson = nil; })
It seems to think abRecordPerson is nil, so I tried to set it, but then I get this error:
CoreData: error: Property
‘setAbRecordPerson:’ is a scalar type
on class ‘Person’ that does not match
its Entity’s property’s scalar type.
Dynamically generated accessors do not
support implicit type coercion.
Cannot generate a setter method for
it.
2011-06-21 20:07:18.100
TestCoreDataLab[79616:207] -[Person
setAbRecordPerson:]: unrecognized
selector sent to instance 0x6d10f40
Any help would be greatly appreciated.
So you’ve defined the getter
-abRecordPerson, but have you created a-setAbPersonRecord? The error seems to indicate that you haven’t, and it looks like that’s the root of the problem.