[英]When using ARC, property values are automatically getting set to nil after being assigned a non-nil value
[英]NSArray and NIL values. How to return the number (“count”) of non-NIL values the array
關於NSArray我有兩個問題:
[NSNull null]
是否正確? 謝謝!!
你不能將nil
添加到NSArray
,所以你必須使用[NSNull null]
而不是你所說的。
您可以通過以下方式計算nil
( NSNull
)項目的數量:
NSIndexSet *nilIndexes = [array indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
return obj == [NSNull null];
}];
NSUInteger count = nilIndexes.count;
[NSNull null]
。 null
對象。 試試這個來自Mike Ash MACollectionUtilities
#define ARRAY(...) ([NSArray arrayWithObjects: IDARRAY(__VA_ARGS__) count: IDCOUNT(__VA_ARGS__)])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.