ios - Swift's ".sort" works on Simulator but not on iPhone -
i have odd problem code have written works fine on iphone simulator not working correctly on phone itself.
basically performing sort on array of objects. sort performed on member of type nsstring.
here class definition:
class event: nsobject { var act: nsstring! var start: nsdate! var end: nsdate! }
here definition of class use wrap collection of event objects.
class events: nsobject { var events = [event]() func add(event: event){ events.append(event) } }
i need sort array in alphabetic order of act. here how doing that:
var result = allevents.values.array [event] sort(&result){$0.act < $1.act string}
the problem is: works in simulator when run on iphone result array in order of initial insertion.
i have tried:
result.sort({$0.act < $1.act string})
but same unsorted result.
any clues doing wrong?
try in events , call when want sort array if does't work make act string! instead of nsstring!
swift 1.2
func sortevents() { events.sort(){ return $0.act.localizedstandardcompare($1.act) == nscomparisonresult.orderedascending } }
swift 2.0
func sortevents() { events.sortinplace(){ return $0.act.localizedstandardcompare($1.act) == nscomparisonresult.orderedascending } }
Comments
Post a Comment