Iphone 访问NSManagedObject中的属性会导致内存峰值和崩溃

Iphone 访问NSManagedObject中的属性会导致内存峰值和崩溃,iphone,memory,core-data,Iphone,Memory,Core Data,我正在编写一个iPhone应用程序,它使用核心数据进行存储。我的所有NSManagedObject子类都是由xcode根据我的数据模型自动生成的。其中一个类如下所示: @interface Client : NSManagedObject { } @property (nonatomic, retain) NSNumber * rate; @property (nonatomic, retain) NSString * name; @property (nonatomic, retain

我正在编写一个iPhone应用程序,它使用核心数据进行存储。我的所有NSManagedObject子类都是由xcode根据我的数据模型自动生成的。其中一个类如下所示:

@interface Client :  NSManagedObject  
{
}

@property (nonatomic, retain) NSNumber * rate;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * description;
@property (nonatomic, retain) NSSet* projects;

@end
self.clientName = [[client.name copy] autorelease];
self.clientRate = [[client.rate copy] autorelease];
self.textView.text = client.description; // This is where it crashes
创建和保存这个类的新实例工作得很好,但是当我尝试访问这样一个实例的“description”属性时,程序意外地退出了。在仪器中运行时,我可以看到,就在崩溃之前,大量内存被快速分配(这可能就是应用程序退出的原因)

访问属性的代码如下所示:

@interface Client :  NSManagedObject  
{
}

@property (nonatomic, retain) NSNumber * rate;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * description;
@property (nonatomic, retain) NSSet* projects;

@end
self.clientName = [[client.name copy] autorelease];
self.clientRate = [[client.rate copy] autorelease];
self.textView.text = client.description; // This is where it crashes
请注意,可以毫无问题地访问其他属性(名称和速率)


那么我做错了什么呢?

来自苹果文档(核心数据编程指南):

请注意,属性名称不能与NSObject或NSManagedObject的任何无参数方法名称相同,例如,不能为属性指定名称“说明”(请参见NSPropertyDescription)


正如jbrennan所指出的,这应该是您遇到的问题的原因。

您不应该使用点符号进行描述,因为它不是一个属性,只是一个方法。当然,点表示法是有效的,但我相信最终它会在编译器或Clang静态分析器中引起警告。是的,就是这样。真是松了一口气!多谢各位!