0

我已经开始了新的 iOS 项目,并且在 ViewControler 头文件中只添加了一个属性。但它给了我错误:

“属性”之前的预期说明符限定符列表

这是代码:

#import <UIKit/UIKit.h>

@interface QuoteGenViewController : UIViewController {

    @property (retain) NSArray *myQuotes;
}

@end
4

2 回答 2

3

Here the general structure of a class interface

@interface Class : Superclass
{
    // Instance variable declarations.
    // Theirs definition could be omitted since you can declare them
    // in the implementation block or synthesize them using declared properties.
}
// Method and property declarations.
@end

Since a property provides a simple way to declare and implement an object’s accessor methods (getter/setter), you need to put them in the Method and property declarations section.

I really suggest to read ocDefiningClasses doc for this.

Hope that helps.

于 2012-06-30T10:35:09.667 回答
2

您的代码应如下所示:

#import <UIKit/UIKit.h>

@interface QuoteGenViewController : UIViewController {

}

@property (retain) NSArray *myQuotes;

@end
于 2012-06-30T09:10:03.920 回答