當我宣佈我的實例變量作爲錯誤:預期標識符或「(」前「公」 - 目標C
@interface FOO : NSObject
{
@public
int a;
}
@public
-(id)init;
-(void)dealloc;
@end
錯誤我收到此錯誤:預期標識符或「(」前「公」
當我宣佈我的實例變量作爲錯誤:預期標識符或「(」前「公」 - 目標C
@interface FOO : NSObject
{
@public
int a;
}
@public
-(id)init;
-(void)dealloc;
@end
錯誤我收到此錯誤:預期標識符或「(」前「公」
,你在頭/接口,將自動公開的方法不要使用@public
或其他訪問關鍵接口定義之外,因爲你不聲明在Objective-C的公共或私有方法。
只要可以從課外公開訪問。如果你只有一個dd是一個實現,但不要在頭文件/接口中公開它(或僅在class extension中公開它),它是私有的。
@interface FOO : NSObject
{
@public
int a;
}
- (id)init;
- (void)dealloc;
@end
現在你爲什麼會想聲明一個公共int a
實例變量(而不是使用屬性)或明確聲明NSObject
已經有兩個方法我是無法理解。
在objective-c方法塊不能包含@public(或@private)塊 - 它只適用於實例變量,並且Objective-c類中的所有方法都是公共的,所以要修復錯誤,請刪除第二個@public代碼:
@interface FOO : NSObject
{
@public
int a;
}
-(id)init;
-(void)dealloc;
@end
你爲什麼要申報公共ivar? – BoltClock 2011-05-11 08:49:46