Search code examples
iosswiftcore-datansorderedset

Find object in NSOrderedSet in CoreData. index(ofAccessibilityElement :)


I have an ordered To Many relationship and Xcode 8 has generated an attribute of type NSOrderedSet with a bunch of helper functions to insert and remove elements.

Now I am trying to find an object and the Apple documentation indicates that the following function is available for NSOrderedSet:

func index(of object: Any) -> Int  

However when I want to use this function the compiler and the autocompletion want me to use the following function instead:

func index(ofAccessibilityElement element: Any) -> Int  

which doesn't seem to be finding anything.

Could someone please help me understand what is going on?


Solution

  • Autocompletion can and often is wrong. It can be handy but it's not a reference for what's correct.

    I don't know what you mean about the compiler wanting to use that method, because it's not what you need to look up objects in an ordered set. The correct method would be index(of:), as in

    var myset = NSMutableOrderedSet(array: [1, 2, 3])
    
    myset.index(of:2)