Reputation: 315
I am trying to sort the NSMutableArray with this piece of code
let sortContacts = contactData! as NSArray as? [String]
print("\(sortContacts.sort())")
I am trying to convert the NSMutableArray to Array of String but when it comes to print("\(sortContacts.sort())")
its giving me nil
Anyone who can suggest me sorting through NSMutableArray?
Upvotes: 0
Views: 43
Reputation: 9923
This works, just make sure your NSMutableArray
contains only string, else use if let
:
let contactData = NSMutableArray(array: ["c","b","a"])
let sortContacts = contactData as NSArray as! [String]
print(sortContacts.sort())
Upvotes: 0