我有一個PersonsArray: NSMutableArray = [NSNull, NSNull, NSNUll, NSNull, NSNull, NSNUll, NSNull]
。我需要七個插槽,然後我可以使用AnyObject填充Entity CoreData條目。如何檢查NSMutableArray元素是NSNull還是AnyObject
我需要爲這個NSMutableArray的循環做...
如果索引插槽NSNull我想傳遞給下一個索引插槽,如果指數位中填充了我的對象我想執行代碼在這個對象上。
example PersonsArray: NSMutableArray = [
NSNull,
NSNull,
NSNull,
"<iswift.Person: 0x7f93d95d6ce0> (entity: Person; id: 0xd000000000080000 <x-coredata://8DD0B78C-C624-4808-9231-1CB419EF8B50/Person/p2> ; data: {\n image = nil;\n name = dustin;\n})",
NSNull,
NSNull,
NSNull
]
試圖
for index in 0..<PersonsArray.count {
if PersonsArray[index] != NSNull {println(index)}
}
表明了一堆的變化沒有任何工作,如
if PersonsArray[index] as! NSNull != NSNull.self {println(index)}
或
if PersonsArray[index] as! NSNull != NSNull() {println(index)}
注意:使用NSNull只是NSMutableArray中的一個佔位符,因此它的計數總是爲7,我可以用一個對象替換任何(7)插槽。我應該使用非NSNull作爲佔位符嗎?
'NSNull'可能定義爲始終從任何'=='或'!='比較中返回'false'。在大多數地方,這是多麼的無效...... – nhgrif