• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Looks KVC-compliant to me, but Cocoa says it ain't
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Looks KVC-compliant to me, but Cocoa says it ain't


  • Subject: Looks KVC-compliant to me, but Cocoa says it ain't
  • From: Jerry Krinock <email@hidden>
  • Date: Wed, 19 Sep 2007 13:38:50 -0700

In order to implement the solution that mmalc gave me last week to my Core Data swimming-meet problem in a demo project, I've written a category on NSMutableSet, which has gotten me into one of those arguments with the Cocoa runtime as to whether or not a class is KVC compliant. As usual, being more stubborn than I, Cocoa is winning...

This code:

// glueClass is a variable of type Class, value is class 'Entry'
id glueObject = [[glueClass alloc] init] ;
NSNumber* position = [[NSNumber alloc] initWithInt:i] ;
// The following sanity test is for debugging...
if (
[glueObject respondsToSelector:@selector(position)]
&& [glueObject respondsToSelector:@selector(setPosition:)]
) {
NSLog(@"%@ responds to setter and getter, looks good!!", glueClass) ;
}
// Now, the trouble...
[glueObject setValue:position forKey:orderKey] ;
NSLog(@"passed!") ;


Produces console output:

Entry responds to setter and getter, looks good!!
[<Entry 0x3d23c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key position.


What could cause the 'not key value coding-compliant' error?

- Entry is declared as a subclass of NSManagedObject
- therefore Entry has no instance variables
- In my .xcdatamodel, I have an Entry entity with
    - class set to 'Entry'
    - 'No Parent Entity'
    - Not 'Abstract'
    - No 'User Info'
    - No 'Configurations'
    - has one 'attribute':
          - name = 'position'
          - not 'Optional'
          - not 'Transient'
          - Type = 'Integer 32'
          - 'Min Value', 'Max Value' and 'Default Value' are blank
    - also has two relationships

One other weird thing that I notice is that if I change the last line in the code above to:

[glueObject setPosition:position] ;

I get exactly the same 'not KVC compliant' error. I think that's weird because setPosition: is not asking any KVC magic; it's just sending a plain-old message to a method which has just passed the - respondsToSelector: test.

Here are the accessors in @implementation Entry (generated by mogenerator, were in superclass @implementation _Entry, doesn't matter if in Entry or _Entry)

- (NSNumber*)position {
   [self willAccessValueForKey:@"position"];
   NSNumber *result = [self primitiveValueForKey:@"position"];
   [self didAccessValueForKey:@"position"];
   return result;
}

- (void)setPosition:(NSNumber*)value_ {
   [self willChangeValueForKey:@"position"];
   [self setPrimitiveValue:value_ forKey:@"position"];
   [self didChangeValueForKey:@"position"];
}

Thanks again folks,

Jerry

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Looks KVC-compliant to me, but Cocoa says it ain't
      • From: "I. Savant" <email@hidden>
References: 
 >Managed Object wants a per-relationship attribute? (From: Jerry Krinock <email@hidden>)
 >Re: Managed Object wants a per-relationship attribute? (From: mmalc crawford <email@hidden>)
 >Re: Managed Object wants a per-relationship attribute? (From: mmalc crawford <email@hidden>)

  • Prev by Date: setting up radio buttons
  • Next by Date: Re: setting up radio buttons
  • Previous by thread: Re: Managed Object wants a per-relationship attribute?
  • Next by thread: Re: Looks KVC-compliant to me, but Cocoa says it ain't
  • Index(es):
    • Date
    • Thread