【发布时间】:2015-02-12 07:38:20
【问题描述】:
我是 Objective C 的新手
我尝试使用简单的struct 并得到了
arc forbids objective-c objects in struct
Looking up ARC,看起来这是定义 Objective C 语法的规范 - 对吗?
其次,如果不允许,我该如何使用struct?
谢谢!
编辑:一些代码作为示例
@implementation Cities {
// The goal is to have a struct that holds information about a city,
// like when a person started and ended living there.
// I was trying to make this struct an instance variable of the Cities
// class
// XCode doesn't like the below struct definition
struct City
{
NSString *name;
int *_startYear;
int *_endYear;
};
}
【问题讨论】:
-
显示代码,为什么要结构体?
-
目前没有特别的原因,我只是在玩代码示例,想知道为什么在使用
struct时会出现上述错误。如果不建议使用,那很好,我不会长期使用它。我对 为什么 它会抛出该错误更感兴趣。谢谢! -
我不记得确切的原因,你可以使用结构,只是不要在其中放置指向类实例的指针。
-
ARC 文档不是 Objective-C 规范。 There is, unfortunately, no such specification.
标签: objective-c struct automatic-ref-counting