issue with an array – returning chaotic value

问题内容:

I have array zoneVibrateCounts[]:-

2017-12-11 06:10:22.815835-0800 slate[7431:2975293] Array: (
4,
1,
1,
10,
1,
1,
1,
1
)

And I try accessing its first element like so:-

NSArray<NSNumber*> *currcount = [SettingsManager shared].zoneVibrateCounts;
value = currcount[0]

Although, the return value im getting is 19, not 4. Any ideas?

问题评论:

答案:

答案1:

Please try this code.

NSArray<NSInteger> *currcount = [SettingsManager shared].zoneVibrateCounts[0];

Or

NSArray<int> *currcount = [SettingsManager shared].zoneVibrateCounts[0];

答案评论:

1  
Using NSInteger: Type argument ‘NSInteger’ (aka ‘long’) is neither an Objective-C object nor a block type . Using int Type argument ‘int’ is neither an Objective-C object nor a block type
– noodlez
1 hour ago
    
What happens if you try this: value = [currcount[0] intValue]
1  
this answer is completely wrong, from a type perspective.
    
You can use type casting for required purpose. @bbum
    
@Jacky – arrays may not contain ints or NSIntegers. They must contain objects. The code in the answer will not compile. Your suggestion in comments to treat the array element as an NSNumber and invoke intValue is correct.

原文地址:

https://stackoverflow.com/questions/47754953/issue-with-an-array-returning-chaotic-value

添加评论

友情链接:蝴蝶教程