1

I have this line in my code:

let argsort = (scores as NSDictionary?)?.keysSortedByValue(using: Selector("compare:"))

but XCode gives me a Use '#selector' instead of explicitly constructing a 'Selector' warning. However, the proposed fix:

let argsort = (scores as NSDictionary?)?.keysSortedByValue(using: #selector(NSTextLocation.compare(_:)))

requires iOS version 15.0, and therefore does not work for me (I am targetting iOS 13.0).

How can I either silence this warning or find a way out of this? Thanks

vib
  • 2,254
  • 2
  • 18
  • 36
  • `let argsort = (scores as NSDictionary?)?.keysSortedByValue(using: #selector(compare(_:)))`. Simply drop the `NSTextLocation.`. And why all of the optionals? – HangarRash Jan 01 '23 at 20:40
  • 1
    BTW - Instead of using `NSDictionary`, use Swift code. See [Sort Dictionary by values in Swift](https://stackoverflow.com/questions/24090016/sort-dictionary-by-values-in-swift) – HangarRash Jan 01 '23 at 20:43
  • Cannot find 'compare' in scope – vib Jan 01 '23 at 20:58
  • 1
    What kind of keys do you have in the dictionary? Change `NSTextLocation.` to whatever class your keys are (assuming it has a `compare:` method. But again, use the Swift solution instead. – HangarRash Jan 01 '23 at 21:12
  • Thanks NSTextLocation was actually the wrong type suggestion.. Should have checked. This is now solved – vib Jan 02 '23 at 20:30

0 Answers0