Skip to content

Instantly share code, notes, and snippets.

@rmnblm
Last active December 12, 2016 07:53

Revisions

  1. Roman Blum renamed this gist Dec 12, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Roman Blum revised this gist Dec 12, 2016. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions optionals_part2.swift
    Original file line number Diff line number Diff line change
    @@ -3,15 +3,15 @@ var firstName: String? = "Roman"
    var lastName: String? = "Blum"

    // Option 1: Nested
    if let unwrappedFirstName = firstName {
    if let unwrappedLastName = lastName {
    // Use unwrappedFirstName and unwrappedLastName
    if let firstName = firstName {
    if let lastName = lastName {
    // Use firstName and lastName
    }
    }

    // Option 2: Seperated by comma
    if
    let unwrappedFirstName = firstName,
    let unwrappedLastName = lastName {
    // Use unwrappedFirstName and unwrappedLastName
    let firstName = firstName,
    let lastName = lastName {
    // Use firstName and lastName
    }
  3. Roman Blum revised this gist Dec 12, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions optionals_part2.swift
    Original file line number Diff line number Diff line change
    @@ -2,14 +2,14 @@
    var firstName: String? = "Roman"
    var lastName: String? = "Blum"

    // Nesting
    // Option 1: Nested
    if let unwrappedFirstName = firstName {
    if let unwrappedLastName = lastName {
    // Use unwrappedFirstName and unwrappedLastName
    }
    }

    // Many optional bindings, seperated by comma
    // Option 2: Seperated by comma
    if
    let unwrappedFirstName = firstName,
    let unwrappedLastName = lastName {
  4. Roman Blum revised this gist Dec 12, 2016. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions optionals_part2.swift
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,16 @@
    var firstName: String? = "Roman"
    var lastName: String? = "Blum"

    // Nesting
    if let unwrappedFirstName = firstName {
    if let unwrappedLastName = lastName {
    // Use unwrappedFirstName and unwrappedLastName
    }
    }

    // Many optional bindings, seperated by comma
    if
    let unwrappedFirstName = firstName,
    let unwrappedLastName = lastName {
    // Use unwrappedFirstName and unwrappedLastName
    }
  5. Roman Blum revised this gist Dec 10, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion optionals_part2.swift
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,6 @@ var lastName: String? = "Blum"

    if let unwrappedFirstName = firstName {
    if let unwrappedLastName = lastName {
    // Do something with unwrappedFirstName and unwrappedLastName
    // Use unwrappedFirstName and unwrappedLastName
    }
    }
  6. Roman Blum revised this gist Dec 9, 2016. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions optionals_part2.swift
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,8 @@
    var firstName: String? = "Roman"
    var lastName: String? = "Blum"

    if let firstName = firstName {
    if let lastName = lastName {
    // Do something with firstName and lastName
    if let unwrappedFirstName = firstName {
    if let unwrappedLastName = lastName {
    // Do something with unwrappedFirstName and unwrappedLastName
    }
    }
  7. Roman Blum created this gist Dec 9, 2016.
    9 changes: 9 additions & 0 deletions optionals_part2.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    // Declare two optional values
    var firstName: String? = "Roman"
    var lastName: String? = "Blum"

    if let firstName = firstName {
    if let lastName = lastName {
    // Do something with firstName and lastName
    }
    }