[MacRuby] #507: valueForKey(key) no longer working with NSManagedObject subclasses.
#507: valueForKey(key) no longer working with NSManagedObject subclasses. -----------------------------------+---------------------------------------- Reporter: johnmacshea@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: valueForKey, KVC, Core Data -----------------------------------+---------------------------------------- In MacRuby 0.4 - any method in an NSManagedObject subclass (or in any other class) could be bound (eg via a controller) to a (view) nscontroller/field. Now - in 0.5 beta 1 and 2 (unless a variable of the same name is a property in the Entity that the NSManagedObject represents) valueForUndefinedKey(key) is called in the subclass, if that method exists, or an error occurs (if valueForUndefinedKey(key) does not exist) - eg: [<Student 0x200391280> valueForUndefinedKey:]: the entity Student is not key value coding-compliant for the key "age". This does not occur in a non NSManagedObject subclass - when view objects are bound to other classes' methods(attributes) - it all works fine. The different version of NSManagedObject valueForKey could be the culprit vis a vis valueForKey in NSObject, but in any case - as mentioned - it worked fine in 0.4. Example project attached. -- Ticket URL: <http://www.macruby.org/trac/ticket/507> MacRuby <http://macruby.org/>
#507: valueForKey(key) no longer working with NSManagedObject subclasses. -----------------------------------+---------------------------------------- Reporter: johnmacshea@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: valueForKey, KVC, Core Data -----------------------------------+---------------------------------------- Comment(by martinlagardette@…): Hi! Could you please try with the latest trunk by downloading the nightly build? (http://www.macruby.org/files/nightlies/) I remember hitting the issue, but after trying to reduce the code which worked, I checked again with your test project, and didn't have any problem with this in `Student.rb`: {{{ #!ruby class Student < NSManagedObject attr_accessor :age end }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/507#comment:1> MacRuby <http://macruby.org/>
#507: valueForKey(key) no longer working with NSManagedObject subclasses. -----------------------------------+---------------------------------------- Reporter: johnmacshea@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: valueForKey, KVC, Core Data -----------------------------------+---------------------------------------- Comment(by martinlagardette@…): Also if you ever want to try, here is the reduced code: {{{ #!ruby framework 'CoreData' class Student < NSManagedObject attr_accessor :age def valueForUndefinedKey(key) p "#{self}::valueForUndefinedKey(#{key})" end end entityDesc = NSEntityDescription.new entityDesc.setName("Student") att = NSAttributeDescription.new att.setAttributeType(NSStringAttributeType) att.setName("age") entityDesc.setProperties([att]) student = Student.alloc.initWithEntity(entityDesc, insertIntoManagedObjectContext:nil) student.setValue("42", forKey:"age") p student.valueForKey("age") }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/507#comment:2> MacRuby <http://macruby.org/>
#507: valueForKey(key) no longer working with NSManagedObject subclasses. -----------------------------------+---------------------------------------- Reporter: johnmacshea@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: valueForKey, KVC, Core Data -----------------------------------+---------------------------------------- Comment(by martinlagardette@…): Sorry, here is a real reduction that will correctly check: {{{ #!ruby framework 'CoreData' class Student < NSManagedObject attr_accessor :age end if ARGV.count < 1 puts "Usage: #{$0} <xcdatamodel file>" exit 1 end # Compile the managed object model so we can open it `/Developer/usr/bin/momc #{ARGV[0]} /tmp/MacRubyCDKeyCheck.mom` model = NSURL.URLWithString("file:///tmp/MacRubyCDKeyCheck.mom") mom = NSManagedObjectModel.alloc.initWithContentsOfURL(model) s = Student.alloc.initWithEntity(mom.entitiesByName["Student"], insertIntoManagedObjectContext:nil) s.valueForKey("age") }}} This works by doing so: {{{ $> macruby kvc.rb ~/Downloads/CDKeyCheck/MacRubyApp.xcdatamodel NSUnknownKeyException: [<Student 0x40073e9a0> valueForUndefinedKey:]: the entity Student is not key value coding-compliant for the key "age". (RuntimeError) $> }}} On trunk: {{{ $> macruby kvc.rb ~/Downloads/CDKeyCheck/MacRubyApp.xcdatamodel nil $> }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/507#comment:3> MacRuby <http://macruby.org/>
#507: valueForKey(key) no longer working with NSManagedObject subclasses. -----------------------------------------+---------------------------------- Reporter: johnmacshea@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: major | Milestone: Component: MacRuby | Resolution: fixed Keywords: valueForKey, KVC, Core Data | -----------------------------------------+---------------------------------- Changes (by martinlagardette@…): * status: new => closed * resolution: => fixed Comment: btw, closing this as it is fixed -- Ticket URL: <http://www.macruby.org/trac/ticket/507#comment:4> MacRuby <http://macruby.org/>
#507: valueForKey(key) no longer working with NSManagedObject subclasses. -----------------------------------------+---------------------------------- Reporter: johnmacshea@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: major | Milestone: MacRuby 0.6 Component: MacRuby | Resolution: fixed Keywords: valueForKey, KVC, Core Data | -----------------------------------------+---------------------------------- Changes (by lsansonetti@…): * milestone: => MacRuby 0.6 -- Ticket URL: <http://www.macruby.org/trac/ticket/507#comment:5> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby