无法将类型 'NSIndexPath' 的值转换为预期的参数类型 'NSIndexPath'
Cannot convert value of type 'NSIndexPath' to expected argument type 'NSIndexPath'
Cannot convert value of type 'NSIndexPath' to expected argument type 'NSIndexPath'
出现错误 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)
}
您正在尝试将下标应用于 obj
,这是 AnyObject
而不是 Array
。
您应该将 obj
转换为 [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
}
}
Cannot convert value of type 'NSIndexPath' to expected argument type 'NSIndexPath'
出现错误 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)
}
您正在尝试将下标应用于 obj
,这是 AnyObject
而不是 Array
。
您应该将 obj
转换为 [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
}
}