Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Don't mourn the removal of --, ++ and the C-style for loop from Swift. Read the blog post:
let baseString = "/Documents/"
let words = ["Alpha", "Beta", "Gamma", "Delta"]
var paths : [String] = []
for (var i = 0; i < words.count; ++i) {
let word = words[i]
for index, word in words.enumerate() {
funcThatRequiresWordAndIndex(word, index: index)
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!
for i in 0..<words.count {
funcThatRequiresWordAndIndex(words[i], index: i)
let baseString = "/Documents/"
let words = ["Alpha", "Beta", "Gamma", "Delta"]
let paths ={"\(baseString)\($0)"})

This comment has been minimized.

Copy link

@SixFiveSoftware SixFiveSoftware commented Dec 24, 2015

Line 1 of IncrementDecrementExample.swift should be var if you're mutating it later in the example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment