OC 中枚举类型放入数组及取出后数值错误的问题
2016-08-31 本文已影响379人
loyt
把枚举值放到数组中,取出后想当然的强转为相应的枚举类型,居然发现是垃圾值。
后来才发现,从数组取出后应该转为NSInteger类型,而不应直接转为对应的枚举类型。
正确的
(LXSBeautyType)[self.typeArray[i] integerValue];
错误的
(LXSBeautyType)self.typeArray[i];


把枚举值放到数组中,取出后想当然的强转为相应的枚举类型,居然发现是垃圾值。
后来才发现,从数组取出后应该转为NSInteger类型,而不应直接转为对应的枚举类型。
正确的
(LXSBeautyType)[self.typeArray[i] integerValue];
错误的
(LXSBeautyType)self.typeArray[i];