iosswiftnsorderedset

How can I add an Object to a NSOrderedSet at the last position?


How the Title says - I want to be sure that the object is on the last position but I cant find any functions for NSOrderedSet. Is it possible to set it simply at data[data.count]?


Solution

  • NSOrderedSet is immutable. You'll need NSMutableOrderedSet, in particular, you'll want to use addObject(_:), such as:

    data.addObject(myData)
    

    NSOrderedSet and NSMutableOrderedSet are both a part of the Foundation framework, and do not conform to the CollectionType protocol, so you cannot use the [] operator like in your question.