![](/img/trans.png)
[英]Objective C: Is there a built-in way to count the total number of items in a 2d /nested NSArray?
[英]How to count the number of items in a NSArray?
我想計算 NSArray
的項目數,並根據它執行一些操作。 我知道這不是什么大不了但我無法得到它。
請提出一些建議。
這很簡單:
int arrayLength = array.count;
[yourNSArrayReference count]
; 很簡單:=)
很簡單:-
[*your array name* count];
你必須檢查一下
[數組計數];
確保您將值聲明為正確的類型,否則您將獲得: Implicit conversion of 'int' to 'x' is disallowed with ARC
。
你可以......
num = [yourArray count];
並且你將得到Implicit conversion loses integer precision: 'NSUInteger' (aka 'unsigned long') to 'int'
那么你應該這樣做:
num = (int)[allValues count];
要么:
num = (int)allValues.count;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.