Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

I have an array of structs.

struct Item {
    let textLabel : NSDate
    let detailTextLabel : NSDate
}

I sorted them with the following code:

myArray.sort{$0.textLabel.compare($1.textLabel) == NSComparisonResult.OrderedAscending}

What's the longer version of the sorting above?

There is a way to make a long version of sorting. Namely the following:

{$0.textLabel.compare($1.textLabel)

Something like this:

func sorterForFileIDASC(this:imageFile, that:imageFile) -> Bool {
  return this.fileID > that.fileID
}

But how would I apply it to my code snippet?

share|improve this question

put on hold as unclear what you're asking by Snowman, MichaelT, Ixrec, durron597, gnat Sep 1 at 4:46

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Unclear what help you need. Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it’s hard to tell what problem you are trying to solve or what aspect of your approach needs to be corrected or explained. See the How to Ask page for help clarifying this question. –  gnat Aug 31 at 19:03
    
Updated question. Hopefully it's clearer now. –  Jessica Aug 31 at 19:09
1  
This appears to be an issue with debugging or implementation - a "how do I do this specific task in this language" question - why didn't you ask it on Stack Overflow? –  MichaelT Aug 31 at 19:09
    
I don't have a problem. The code is working fine. I just have a hard time reading the short version –  Jessica Aug 31 at 19:10
    
I actually find the shorter version easier to read. The expression between the braces is essentially equivalent to your anonymous method in the second version; you're just not explicitly wrapping the expression in a func in the first version. –  Robert Harvey Aug 31 at 19:35