# Unrecognized selector sent to instance

**URL:** <https://forums.kodeco.com/t/unrecognized-selector-sent-to-instance/20209>\
**Category:** iOS\
**Created:** [September 23, 2016, 12:28am UTC](https://forums.kodeco.com/t/unrecognized-selector-sent-to-instance/20209 "2016-09-23T00:28:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonny](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jonny/32/79544_2.png) [@jonny](https://forums.kodeco.com/u/jonny)\
**Post date:** [September 23, 2016, 12:28am UTC](https://forums.kodeco.com/t/unrecognized-selector-sent-to-instance/20209/1 "2016-09-23T00:28:38Z")

</div>

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*** `

---

<div class="post-metadata">

**Author:** ![aeberbach](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/aeberbach/32/81494_2.png) [@aeberbach](https://forums.kodeco.com/u/aeberbach)\
**Post date:** [September 23, 2016, 12:49am UTC](https://forums.kodeco.com/t/unrecognized-selector-sent-to-instance/20209/2 "2016-09-23T00:49:57Z")

</div>

> [@jonny](#):
>
> NSFetchedResultsController

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](http://stackoverflow.com/a/38036951/189804).

---

<div class="post-metadata">

**Author:** ![jonny](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jonny/32/79544_2.png) [@jonny](https://forums.kodeco.com/u/jonny)\
**Post date:** [September 23, 2016, 12:52am UTC](https://forums.kodeco.com/t/unrecognized-selector-sent-to-instance/20209/3 "2016-09-23T00:52:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![aeberbach](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/aeberbach/32/81494_2.png) [@aeberbach](https://forums.kodeco.com/u/aeberbach)\
**Post date:** [September 23, 2016, 1:27am UTC](https://forums.kodeco.com/t/unrecognized-selector-sent-to-instance/20209/4 "2016-09-23T01:27:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jonny](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jonny/32/79544_2.png) [@jonny](https://forums.kodeco.com/u/jonny)\
**Post date:** [September 23, 2016, 1:40am UTC](https://forums.kodeco.com/t/unrecognized-selector-sent-to-instance/20209/5 "2016-09-23T01:40:00Z")

</div>

`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

---

<div class="post-metadata">

**Author:** ![jonny](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jonny/32/79544_2.png) [@jonny](https://forums.kodeco.com/u/jonny)\
**Post date:** [September 23, 2016, 1:47am UTC](https://forums.kodeco.com/t/unrecognized-selector-sent-to-instance/20209/6 "2016-09-23T01:47:17Z")

</div>

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

```
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)

```

---

<div class="post-metadata">

**Author:** ![aeberbach](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/aeberbach/32/81494_2.png) [@aeberbach](https://forums.kodeco.com/u/aeberbach)\
**Post date:** [September 23, 2016, 3:02am UTC](https://forums.kodeco.com/t/unrecognized-selector-sent-to-instance/20209/7 "2016-09-23T03:02:36Z")

</div>

It does look right to me - does it work?

---

<div class="post-metadata">

**Author:** ![jonny](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jonny/32/79544_2.png) [@jonny](https://forums.kodeco.com/u/jonny)\
**Post date:** [September 23, 2016, 11:55am UTC](https://forums.kodeco.com/t/unrecognized-selector-sent-to-instance/20209/8 "2016-09-23T11:55:43Z")

</div>

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