iOS coredata:如何为@dynamic生成的core data属性的访问器设置断点

iOS coredata:如何为@dynamic生成的core data属性的访问器设置断点,ios,core-data,Ios,Core Data,只需使用符号断点,如-[EntityName setAttribute://code>不起作用。您仍然可以覆盖@dynamic accessor ... @dynamic stringAttribute; ... -(NSString *)stringAttribute { return stringAttribute; // breakpoint here. } 德韦恩 核心数据访问器并不复杂,但也不是标准的。如果您想要捕获一个,并且CD仍能正常运行,那么访问器需要

只需使用符号断点,如
-[EntityName setAttribute://code>不起作用。

您仍然可以覆盖@dynamic accessor

...
@dynamic stringAttribute;
...

-(NSString *)stringAttribute {
    return stringAttribute;         // breakpoint here.
}
德韦恩

核心数据访问器并不复杂,但也不是标准的。如果您想要捕获一个,并且CD仍能正常运行,那么访问器需要比上面列出的Mundi更多的支持。(他的回答在设计和意图上都是正确的,只是不完整。)


Andrew

可能重复@Valentiradu:核心数据在运行时生成动态访问器方法,在上设置符号断点是不可能的(或至少是困难的)。作为一种解决方法,您可以提供一个自定义访问器方法,如上述副本的答案所示。下面给出了一个非常类似的解决方案。我不知道为什么这是一个“不是真正的问题”,我投票将其作为“重复”关闭。如果你读了标题,那么问题就很清楚了。核心数据属性没有实例变量备份,因此我怀疑这是否有效。你是对的,没有下划线,除非你自己声明变量(这也是可行的)。
...
@property (nonatomic) NSString *primitiveStringAttribute;
...
@dynamic stringAttribute, primitiveStringAttribute;
...
- (NSString *) stringAttribute {

  NSString *attribute = nil;

  [self willAccessValueForKey: @"stringAttribute"];

  attribute = self.primitiveStringAttribute;

  [self  didAccessValueForKey: @"stringAttribute"];

  return attribute;
}