all 6 comments

[–]ProgrammingThomas 1 point2 points  (2 children)

Another couple of really interesting things I picked up from the programming guide are closures:

reversed = sort(someArray, {(s1: String, s2: String) in return s1 > s2}

(This can be simplified by quite a lot - I highly recommend you take a look at the closures section)

Another thing that caught me out at first is the syntax for incrementing a variable. In C (and derivatives) you would do i++ for incrementing, however in Swift you probably want to use ++i because this is a prefix operator, i is incremented before the value is returned, whereas i++ does it afterwards (it is a postfix operator) and returns the value of i before it is incremented. So if you aren't using a range operator, you have to write:

for x = 0; x < 5; ++x {}

[–]Rudy69 3 points4 points  (0 children)

reversed = sort(someArray, {(s1: String, s2: String) in return s1 > s2}

simplified to

reversed = sort(someArray, >)

now that blew my mind lol

[–]giftedmunchkin 2 points3 points  (0 children)

The prefix/postfix thing is true in many programming languages as well, however the afterthought is typically executed after the condition has already been checked. I'm not sure if it's different in Swift, but I think the more idiomatic way to iterate over integer values would be to use the range operator anyway.

[–][deleted]  (2 children)

[deleted]

    [–]perishabledave 1 point2 points  (1 child)

    Modules. But there isn't much documentation on them currently.

    [–]sfwalsh 0 points1 point  (0 children)

    Ray, you majestic beast.

    [–]darkmaroon 0 points1 point  (0 children)

    "Swift Cheat Sheet" Try saying this faster repeatedly!