我想在接下來的情況下使用NS_OPTIONS:NS_OPTIONS超過8個值
typedef NS_OPTIONS(NSUInteger, FZAnimalType) {
FZAnimalTypeNone = 0,
FZAnimalTypeBear = 1 << 0,
FZAnimalTypeFox = 1 << 1,
FZAnimalTypeWolf = 1 << 2,
FZAnimalTypeTiger = 1 << 3,
FZAnimalTypeLion = 1 << 4,
FZAnimalTypeRabbit = 1 << 5,
FZAnimalTypeGoat = 1 << 6,
FZAnimalTypeParrot = 1 << 7,
FZAnimalTypeDog = 1 << 8,
FZAnimalTypeCat = 1 << 9,
FZAnimalTypeSheep = 1 << 10,
FZAnimalTypeEagle = 1 << 11
};
而且我有一個警告:
隱式轉換損失整數精度:「無符號整型」到「 BOOL」(又名 '符號字符')
去年4行下面的代碼:
zoo.hasBear = registry.animalTypes & FZAnimalTypeBear;
zoo.hasFox = registry.animalTypes & FZAnimalTypeFox;
zoo.hasWolf = registry.animalTypes & FZAnimalTypeWolf;
zoo.hasTiger = registry.animalTypes & FZAnimalTypeTiger;
zoo.hasLion = registry.animalTypes & FZAnimalTypeLion;
zoo.hasRabbit = registry.animalTypes & FZAnimalTypeRabbit;
zoo.hasGoat = registry.animalTypes & FZAnimalTypeGoat;
zoo.hasParrot = registry.animalTypes & FZAnimalTypeParrot;
zoo.hasDog = registry.animalTypes & FZAnimalTypeDog;
zoo.hasCat = registry.animalTypes & FZAnimalTypeCat;
zoo.hasSheep = registry.animalTypes & FZAnimalTypeSheep;
zoo.hasEagle = registry.animalTypes & FZAnimalTypeEagle;
屬性hasDog/hasCat/hasSheep/hasEagle - always NO。 本帖子中的解決方案:64-bit NS_OPTIONS bitmask沒有幫助我。我究竟做錯了什麼?
你應該做'zoo.hasEagle =(registry.animalTypes&FZAnimalTypeEagle)== FZAnimalTypeEagle' – dan
後頭部代碼定義你的動物園和註冊表的結構檢查位。 –
的評論,它的工作原理的答案 –