私は次のようなことをしようとしています
int ItemNames;
typedef enum ItemNames {apple, club, vial} ItemNames;
+(BOOL)GetInventoryItems{return ItemNames;}
apple=1; //Compiler Error.
問題は、列挙型の変数を新しい値に設定できないことです。コンパイラは、列挙型で整数を「再宣言」したことを通知します。また、値が正しく返されません。代わりに、各アイテムに if ステートメントを使用して、そのように存在するかどうかを確認する必要があります。
+ (void)GetInventoryItems
{
if (apple <= 1){NSLog(@"Player has apple");}
if (club <= 1){ NSLog(@"Player has club");}
if (vial <= 1){NSLog(@"Player has vial");}
if (apple == 0 && club == 0 && vial == 0){NSLog(@"Player's Inventory is Empty.");}
}
回避策はありますか?