ios – Objective-C方法’controller:didChangeObject:atIndexPath:forChangeType:newIndexPath

前端之家收集整理的这篇文章主要介绍了ios – Objective-C方法’controller:didChangeObject:atIndexPath:forChangeType:newIndexPath前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Objective-C method ‘controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:’ provided by method ‘controller(:didChangeObject:atIndexPath:forChangeType:newIndexPath:)’ conflicts with optional requirement method ‘controller(:didChangeObject:atIndexPath:forChangeType:newIndexPath:)’ in protocol ‘NSFetchedResultsControllerDelegate’

func controller(controller: NSFetchedResultsController,didChangeObject anObject: NSManagedObject,atIndexPath indexPath: NSIndexPath?,forChangeType type: NSFetchedResultsChangeType,newIndexPath: NSIndexPath?) {
    if self.collectionView?.window == nil {
        return
    }

    let change = NSMutableDictionary()

    switch(type)
    {
    case .Insert:
        change[NSNumber(unsignedLong:type.rawValue)] = newIndexPath
    case .Delete:
        change[NSNumber(unsignedLong:type.rawValue)] = indexPath
    case .Update:
        change[NSNumber(unsignedLong:type.rawValue)] = indexPath
    case .Move:
        change[NSNumber(unsignedLong:type.rawValue)] = NSArray(objects: indexPath!,newIndexPath!)
    default:
        break
    }
    self.objectChanges?.addObject(change)
}

解决方法

看起来正确的方法签名是:
func controller(controller: NSFetchedResultsController,didChangeObject anObject: AnyObject,newIndexPath: NSIndexPath?) {

}

解决这些问题的任何简单方法是允许Xcode自动完成方法签名.然后,用自动生成的签名替换方法的签名.为此,您只需在定义方法时键入controller以查看匹配的所有方法的列表.

原文链接:https://www.f2er.com/iOS/328580.html

猜你在找的iOS相关文章