简体   繁体   English

无法将'NSIndexPath'类型的值转换为预期的参数类型'NSIndexPath'

[英]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.

相关问题 无法使用Int类型下标类型'[NSIndexPath]'的值 - Cannot subscript a value of type '[NSIndexPath]' with a type Int 无法在 Swift 中将“UITableViewCell”类型的值转换为“NSIndexPath” - Could not cast value of type 'UITableViewCell' to 'NSIndexPath' in Swift 无法将TableViewCell类型的值强制转换为“ NSIndexPath” - Could not cast value of type TableViewCell to 'NSIndexPath' 无法将类型的值转换为预期的参数Firebase - Cannot convert value of type to expected argument Firebase 无法将类型'()'的值转换为预期的参数'()-> void' - cannot convert value of type '()' to expected argument '() -> void' 无法转换期望参数类型GTLServiceCompletionHandler的值 - Cannot convert value of expected argument type GTLServiceCompletionHandler 无法将类型'String?.Type'的值转换为预期的参数类型'String?' - Cannot convert value of type 'String?.Type' to expected argument type 'String?' 无法将“(QueryDocumentSnapshot).Type”类型的值转换为预期的参数类型“QueryDocumentSnapshot” - cannot convert value of type '(QueryDocumentSnapshot).Type' to expected argument type 'QueryDocumentSnapshot' 无法将类型“ [[ModelName]?]”的值转换为预期的参数类型“ [ModelName] .Type” - Cannot convert value of type '[[ModelName]?]' to expected argument type '[ModelName].Type' 无法将 [Type] 类型的值转换为预期的参数类型“some View” - Cannot convert value of type [Type] to expected argument type 'some View'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM