我有一个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