Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C method 'controller:didChangeObject:atIndexPath:forChangeType:newIndexPath

Tags:

ios

swift

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)
}
like image 703
mosaic6 Avatar asked Sep 25 '15 21:09

mosaic6


1 Answers

It looks like the proper method signature is:

func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {

}

Any easy way to fix these problems is to allow Xcode to autocomplete the method signature. Then, replace your method's signature with the auto generated signature. For this, you just need to type controller when defining a method to see the list of all methods that match.

like image 105
TheRobDay Avatar answered Nov 04 '22 07:11

TheRobDay