Last active
June 27, 2019 16:19
-
-
Save JoshuaSullivan/72cfabb9ac63aa2721d5 to your computer and use it in GitHub Desktop.
Don't mourn the removal of --, ++ and the C-style for loop from Swift. Read the blog post: http://www.chibicode.org/?p=24
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let baseString = "/Documents/" | |
let words = ["Alpha", "Beta", "Gamma", "Delta"] | |
var paths : [String] = [] | |
for (var i = 0; i < words.count; ++i) { | |
let word = words[i] | |
paths.append("\(baseString)\(word)") | |
} | |
print(paths) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for index, word in words.enumerate() { | |
funcThatRequiresWordAndIndex(word, index: index) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let n = 4 | |
print(--n) // Prints '3', value of n is now 3. | |
print(++n) // Prints '4', value of n is now 4. | |
print(n--) // Prints '4', value of n is now 3. Confusing! | |
print(n++) // Prints '3', value of n is now 4. Also confusing! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in 0..<words.count { | |
funcThatRequiresWordAndIndex(words[i], index: i) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let baseString = "/Documents/" | |
let words = ["Alpha", "Beta", "Gamma", "Delta"] | |
let paths = words.map({"\(baseString)\($0)"}) | |
print(paths) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 1 of IncrementDecrementExample.swift should be
var
if you're mutating it later in the example.