Unrecognized selector sent to instance

Hi

I am having a weird problem occur. I have made a screen that creates a new Football Fixture.
I take in an opposition (UITextField), a game date (date) and then I have a dropdown that is powered by a another core Date object that lists all of my teams (Team object).

Now I can add and edit Games fine and view them in the table. But when I try to make my tableView work by breaking my Games into a team section I am having problems.

I have two available teams that I can pick from when creating/editing a Football Fixture. But I am unable to update or create a fixture when the second Team is selected.

I have included my code, which works when no sections are involved. And commented out the pieces that are seeming to break it:

  //let sortDescriptor1 = NSSortDescriptor(key: "gameBelongsTo", ascending: true)
    let sortDescriptor2 = NSSortDescriptor(key: "date", ascending: true)
    fetchRequest.sortDescriptors = [/*sortDescriptor1,*/ sortDescriptor2]
    fetchRequest.fetchBatchSize = 20
    let fetchedResultsController = NSFetchedResultsController(
        fetchRequest: fetchRequest,
        managedObjectContext: self.managedObjectContext,
        sectionNameKeyPath: nil, //"gameBelongsTo.name",
        cacheName: nil)

I should add the date is an attribute on the Game model. but the gameBelongsTo is a relation. That is from the Game and relates to the Team that this game is associated with.

This is the error I am getting, which is confusing me. Any help would be greatly appreciated

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: unrecognized selector sent to instance ***

Have you recently updated to Xcode 8/iOS 10? NSFetchedResultsController has changed to be a generic and you may need to initialise it in a new way, specifying type.

I haven’t no. I wanted to try and get more app going in Swift 2.2 and then take on the upgrade to XCode 8 and Swift 3.

So what kind of object is at the end of the gameBelongsTo relationship, and are you 100% sure it has a “name” attribute?

gameBelongsTo has a destination of Team and the Team has an attribute called name.
It displays in my UIPicker fine and this works when I don’t try to use sections in my TableView

I think Ii’ve fixed it?? Does this seem right? (I appreciate your help with all my Questions :slight_smile: )

let sortDescriptor1 = NSSortDescriptor(key: "gameBelongsTo.name", ascending: true) // this was "gameBelongsTo" and not "gameBelongsTo.name"
let sortDescriptor2 = NSSortDescriptor(key: "date", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor1,sortDescriptor2]
fetchRequest.fetchBatchSize = 20
let fetchedResultsController = NSFetchedResultsController(
    fetchRequest: fetchRequest,
    managedObjectContext: self.managedObjectContext,
    sectionNameKeyPath: "gameBelongsTo.name",
    cacheName: nil)

It does look right to me - does it work?

Yeah, seems to be fine. Appreciate your help with my dodgy questions :grinning: