Skip to content

Instantly share code, notes, and snippets.

@mateuszszklarek
Created February 1, 2019 18:06
Show Gist options
  • Select an option

  • Save mateuszszklarek/f82c9a8df678596fe8f625963d94b874 to your computer and use it in GitHub Desktop.

Select an option

Save mateuszszklarek/f82c9a8df678596fe8f625963d94b874 to your computer and use it in GitHub Desktop.

Revisions

  1. mateuszszklarek created this gist Feb 1, 2019.
    19 changes: 19 additions & 0 deletions optional_chain.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    class CustomObject {

    func value() -> Int {
    return 5
    }

    func optionalValue() -> Int? {
    return nil
    }

    }

    var optionalObject: CustomObject? = CustomObject()
    let x = optionalObject?.value()
    let y = optionalObject?.optionalValue()

    print("Type of x: \(type(of: x))\nType of y: \(type(of: y))")
    // Type of x: Optional<Int>
    // Type of y: Optional<Int>