Skip to content

Instantly share code, notes, and snippets.

@mateuszszklarek
Created February 1, 2019 18:07
Show Gist options
  • Save mateuszszklarek/391c5000bd21122a9e18c9f479cd8510 to your computer and use it in GitHub Desktop.
Save mateuszszklarek/391c5000bd21122a9e18c9f479cd8510 to your computer and use it in GitHub Desktop.
class CustomObject {
func value() throws -> Int {
return 5
}
func optionalValue() throws -> Int? {
return nil
}
}
let object = CustomObject()
let x = try? object.value()
let y = try? object.optionalValue()
print("Type of x: \(type(of: x))\nType of y: \(type(of: y))")
// Swift 4.2
// Type of x: Optional<Int>
// Type of y: Optional<Optional<Int>>
// Swift 5
// Type of x: Optional<Int>
// Type of y: Optional<Int>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment