开发者

why isn't the debugger aware of methods on my Core Data generated managed object classes? (code attached)

why isn't the debugger aware of methods on my Core Data generated managed object classes? (code attached) So:

  • I have an XCode generated managed Core Data object class called WEView
  • I notice the debugger don't seem to be aware of it's methods?
  • See开发者_高级运维 below in the console output. The initial "po self.weView" seems to work, but then when referring any of the objects instance variables doesn't?

Console Output

(gdb) po self.weView
<WEView: 0x4f6a3f0> (entity: WEView; id: 0x4f68710 <x-coredata://CB3E1660-4BA8-4700-ADDB-A32CD44D56B6/WEView/p3> ; data: {
    title = "Weekend Items";
    weEndDayTime = "(...not nil..)";
    weStartDayTime = "(...not nil..)";
})
(gdb) po self.weView.title
There is no member named title.
(gdb) po [self.weView title]
Target does not respond to this message selector.
(gdb) 

header - produced by Xcode

@interface WEView : NSManagedObject {
@private
}
@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) id weStartDayTime;
@property (nonatomic, retain) id weEndDayTime;

@end


Thats because there really is no ivar named title and also no getter or setter pair. Thats also why you use @dynamic and not @synthesize. When you access eg. title, this will be something like this in reality:

[myObject valueForKey:@"title"];

Likewise, setting the title is something like this:

[myObject setValue:foo forKey:@"title"];

So basically is a NSManagedObject just a wrapper around a database fetch or a access from the cache, but you will never access some real ivars of the object (you can try the runtime functions to determine the ivars of an NSManagedObject subclass).

If you still want to use the [self.view title], you need to overwrite it. Here is an example:

- (NSString *)title
{
   NSString *value;
   [self willAccessValueForKey:@"title"];
   value = [self primitiveValueForKey:@"title"];
   [self didAccessValueForKey:@"title"];

   return value;
}

Of course thats not a atomic getter and its slower than the normal way, but hey, it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜