我是Objective-C的新手,但现在编码已经很多年了。不知何故,我对Objective-C不感兴趣。我搜索谷歌和stackoverflow,但我认为我的问题只是简单和愚蠢的,没有人问过这个呢。Objective-C属性访问:发送到实例的无法识别的选择器
我的代码基于DateSelectionTitles示例。 http://developer.apple.com/library/ios/#samplecode/DateSectionTitles/Introduction/Intro.html
我有一个NSManagedObject
@interface Event : NSManagedObject
@property (nonatomic, retain) NSDate * date;
...
// Cache
@property (nonatomic, retain) NSString * primitiveSectionIdentifier;
所有性质鉴别仪表,都在我的数据模型定义,除了primitiveSectionIdentifier(如苹果的例子)
但是,当我打电话
NSString *tmp = [self primitiveSectionIdentifier];
我获得例外
Termina由于未捕获的异常 'NSInvalidArgumentException',原因婷应用: ' - [事件primitiveSectionIdentifier]:无法识别的选择发送到实例0x74850c0'
说得简单:
Event *foo = [[Event alloc] init];
if (foo.primitiveSectionIdentifier) {
NSLog(@"YEAH");
}
抛出同样的异常。所以我基本上想检查primitiveSectionIdentifier是否为零。但是当我访问属性时,它会抛出异常?在我能检查它的价值之前,我是否需要分配每个属性?
哪个Objective-C基础知识我不在这里?
非常感谢回复!
你在'@ implementation'部分编写了'@synthesize primitiveSectionIdentifier;'吗? – 2012-11-01 17:19:53
您的代码编译时是否没有警告? – rmaddy
如果您使用的是Xcode 4。5编译器不会给出不合成警告(@synthesize属性)。改为尝试使用self.primitiveSectionIdentifier。在Xcode 4.5发布说明中提到https://developer.apple.com/library/mac/#releasenotes/DeveloperTools/RN-Xcode/_index.html –