Skip to content

Instantly share code, notes, and snippets.

@tikitu
Created January 20, 2017 12:04
Show Gist options
  • Save tikitu/db54e63edb31b3ef3148e257573db50c to your computer and use it in GitHub Desktop.
Save tikitu/db54e63edb31b3ef3148e257573db50c to your computer and use it in GitHub Desktop.
Inconsistent implicit type conversions in Swift
Welcome to Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1). Type :help for assistance.
1> let an_int: Int = 3
an_int: Int = 3
2> an_int is Int?
$R0: Bool = true
3> [an_int] is [Int?]
$R1: Bool = true
4> let list_of_ints = [an_int]
list_of_ints: [Int] = 1 value {
[0] = 3
}
5> list_of_ints is [Int?]
error: repl.swift:5:14: error: 'Int?' is not a subtype of 'Int'
list_of_ints is [Int?]
~~~~~~~~~~~~~^~~~~~~~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment