Skip to content

Instantly share code, notes, and snippets.

@JoshuaSullivan
Last active June 27, 2019 16:19
Show Gist options
  • Select an option

  • Save JoshuaSullivan/72cfabb9ac63aa2721d5 to your computer and use it in GitHub Desktop.

Select an option

Save JoshuaSullivan/72cfabb9ac63aa2721d5 to your computer and use it in GitHub Desktop.

Revisions

  1. JoshuaSullivan revised this gist Dec 24, 2015. No changes.
  2. JoshuaSullivan created this gist Dec 23, 2015.
    9 changes: 9 additions & 0 deletions CForLoopExample.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    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)
    3 changes: 3 additions & 0 deletions EnumerateExample.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    for index, word in words.enumerate() {
    funcThatRequiresWordAndIndex(word, index: index)
    }
    5 changes: 5 additions & 0 deletions IncrementDecrementExample.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    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!
    3 changes: 3 additions & 0 deletions IterateRangeExample.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    for i in 0..<words.count {
    funcThatRequiresWordAndIndex(words[i], index: i)
    }
    5 changes: 5 additions & 0 deletions MapExample.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    let baseString = "/Documents/"
    let words = ["Alpha", "Beta", "Gamma", "Delta"]

    let paths = words.map({"\(baseString)\($0)"})
    print(paths)