[英]Cannot convert value of type 'NSIndexPath' to expected argument type 'NSIndexPath'
Cannot convert value of type 'NSIndexPath' to expected argument type 'NSIndexPath' 无法将'NSIndexPath'类型的值转换为预期的参数类型'NSIndexPath'
Error is on self.collectionView?.moveItemAtIndexPath(obj[0] as! NSIndexPath, toIndexPath: obj[1] as! NSIndexPath) line
错误在self.collectionView?.moveItemAtIndexPath(obj[0] as! NSIndexPath, toIndexPath: obj[1] as! NSIndexPath) line
if let changes = self.objectChanges{
self.collectionView?.performBatchUpdates({ () -> Void in
for change in changes as NSArray as! [NSDictionary] {
change.enumerateKeysAndObjectsUsingBlock { (keyObject:AnyObject!, obj:AnyObject!, stop) -> Void in
let key = keyObject as! NSNumber
let type = NSFetchedResultsChangeType(rawValue: key.unsignedLongValue)!
switch (type)
{
case .Insert:
self.collectionView?.insertItemsAtIndexPaths(obj as! ([NSIndexPath]))
case .Delete:
self.collectionView?.deleteItemsAtIndexPaths(obj as! ([NSIndexPath]))
case .Update:
self.collectionView?.reloadItemsAtIndexPaths(obj as! ([NSIndexPath]))
case .Move:
self.collectionView?.moveItemAtIndexPath(obj[0] as! NSIndexPath, toIndexPath: obj[1] as! NSIndexPath)
default:
break
}
}
}
}, completion: nil)
}
You are trying to apply subscript to obj
which is AnyObject
not Array
. 您正在尝试将下标应用于obj
,即AnyObject
而不是Array
。 You should cast obj
to [NSIndexPath]
: 你应该把obj
[NSIndexPath]
为[NSIndexPath]
:
if let obj = obj as? [NSIndexPath] {
switch (type) {
case .Insert:
self.collectionView?.insertItemsAtIndexPaths(obj)
case .Delete:
self.collectionView?.deleteItemsAtIndexPaths(obj)
case .Update:
self.collectionView?.reloadItemsAtIndexPaths(obj)
case .Move:
self.collectionView?.moveItemAtIndexPath(obj[0], toIndexPath: obj[1])
default:
break
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.