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以查看匹配的所有方法的列表.