Sorted is not working in Xcode 7

851 views Asked by At

I used sorted method in Swift in Xcode 6.3 as

sorted(UIFont.fontNamesForFamilyName(familyName) as! [String])

I downloaded Xcode 7 beta, it says "sorted in unavailable, call sort on the collection". Any idea what is going wrong?

1

There are 1 answers

1
mustafa On BEST ANSWER

Many free functions in swift 1.2 now moved into protocol extensions

(UIFont.fontNamesForFamilyName(familyName) as! [String]).sortInPlace()

In swift book protocol extensions explained like this

Protocols can be extended to provide method and property implementations to conforming types. This allows you to define behavior on protocols themselves, rather than in each type’s individual conformance or in a global function.