-
-
Save rdela/10ef5c4a869ca6d0880c0765c17d500b 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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