Swift's ".sort" works on Simulator but not on iPhone

I have an odd problem where some code I have written works fine on the iPhone Simulator but not working correctly on the phone itself.

Basically I am performing a sort on an array of objects. The sort is to be performed on a member of type NSString.

Here is my class definition:

class Event: NSObject {

    var act: NSString!
    var start: NSDate!
    var end: NSDate!

here is definition of a class I use to wrap a collection of the Event objects.

class Events: NSObject {
    var events = [Event]()

    func add(event: Event){

I need to sort the array so I get in alphabetic order of the act. Here is how I am doing that:

var result = allEvents.values.array as [Event]
sort(&result){$0.act < $1.act as String}

The problem is: this works perfectly in the simulator but when run on the iPhone the result array is in the order of initial insertion.

I have also tried:

result.sort({$0.act < $1.act as String})

But I get the same unsorted result.

Any clues as to what I am doing wrong?


Try this in events and call it when you want to sort the array If this does't work than make act an 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              }

Need Your Help

Protocol for remote logging of temperature, gas/electricity consumption

api networking logging messaging sensor

So, I'm managing a series of rented holiday homes, which all have dynamic IP, ADSL Internet connections.

NullReferenceException in DotNetOpenAuth

asp.net-mvc oauth nuget dotnetopenauth integrated-pipeline-mode

I tracked down what appears to be a defect causing a NullReferenceException in my ASP.NET MVC app. Did I break this, or should this break DotNetOpenAuth for the majority of installations?