我都設有這樣一個定義枚舉:從法的目標C返回枚舉
typedef enum{
apple,
banana
}Fruits;
,我想創建方法,返回此枚舉像這樣的:
-(Fruits)getFruits;
但是當我像這樣使用它我得到了錯誤:Objective-C消息具有不完整的結果類型'enum Fruits'。
有人嗎?
我都設有這樣一個定義枚舉:從法的目標C返回枚舉
typedef enum{
apple,
banana
}Fruits;
,我想創建方法,返回此枚舉像這樣的:
-(Fruits)getFruits;
但是當我像這樣使用它我得到了錯誤:Objective-C消息具有不完整的結果類型'enum Fruits'。
有人嗎?
要創建的枚舉可能工作過的樣子,我還沒有嘗試過,但我一直創建我的枚舉是這樣的:
enum Fruits
{
apple,
banana,
peach,
pear
};
當您創建函數,返回值必須爲enum Fruits
,不只是Fruits
:
-(enum Fruits) getFruits;
另外,還要確保你#import
包含枚舉定義的文件。例如,如果您有一個名爲ApplicationEnums.h
文件,該枚舉定義是,下面的行添加到包含getFruits
函數的文件的頂部:
#import "ApplicationEnums.h"
更新2014.現在首選的方法是使用NS_ENUM宏(請參閱Robotic Cat的答案) – PapillonUK
聽起來好像您還沒有導入包含enum
定義的文件。
另外,Apple提供了一個宏來幫助枚舉定義並幫助完成代碼。例如:
typedef NS_ENUM(NSInteger, Fruits) {
Fruits_Apple,
Fruits_Banana,
Anything_you_want
};
導入包含枚舉定義的文件。 –