Objective-C错误:属性'active'是类'Routine'上的标量类型。无法为其生成getter方法 [英] Objective-C error: Property 'active' is a scalar type on class 'Routine'. Cannot generate a getter method for it

查看:124
本文介绍了Objective-C错误:属性'active'是类'Routine'上的标量类型。无法为其生成getter方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iphone模拟器(3.0操作系统)中运行以下错误时收到以上错误:

I'm getting the above error when the following runs in the iphone simulator (3.0 OS):

@interface Routine : NSManagedObject {

}

@property (nonatomic) BOOL active;

@implementation Routine
@dynamic active
@end

你可以看到,我是继承NSManagedObject,因为我使用Core Data。在我的数据模型中,active是布尔类型的选项属性。

As you can see, I'm subclassing NSManagedObject because I'm using Core Data. In my data model, "active" is an option attribute of type Boolean.

我在这里做什么错误?

谢谢!

推荐答案

从CD中产生的一切都是一个对象,而不是一个scaler。因此,将您的代码更改为:

Everything that comes out of CD is an object, not a scaler. So, changer your code to:

@interface Routine : NSManagedObject {

}

@property (nonatomic) NSNumber * active;

@implementation Routine
@dynamic active
@end

如果你想要你可以添加一个方便的访问器作为一个标量处理它:

If you want you can add a convenience accessor to deal with it as a scalar:

- (BOOL) activeScalar {
  return self.active.boolValue;
}

- (void) setActiveScalar:(BOOL)active_ {
  self.active = [NSNumber numberWithBool:active_];
}



最后,如果您在模型编辑器中按住Control键点击属性打开一个巨大的上下文菜单,包括将适当的声明和定义复制到粘贴板中的选项,因此您不必自己编写它们。

Finally, if you control-click on a property in the model editor it will bring up an enormous contextual menu, including options to copy the appropriate declarations and definitions into your paste board, so you don't have to write them yourself.

这篇关于Objective-C错误:属性'active'是类'Routine'上的标量类型。无法为其生成getter方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆