小出しシリーズです。Swift本読んで思ったことをつらつら書いています。
SwiftのnillはObjective-Cのnillとは違うようです。Objective-Cではnilは存在しないオブジェクトに対するポインタですが、Swiftではポインタではなく、ある型の値がないことを示しています。nillを許容するためにはOptionalでラップする必要があるのですが、オブジェクトの型だけでなく、あらゆる型をラップしてnillをセットできるようです。
“Swift’s nil is not the same as nil in Objective-C. In Objective-C, nil is a pointer to a non-existent object. In Swift, nil is not a pointer—it is the absence of a value of a certain type. Optionals of any type can be set to nil, not just object types.”
抜粋:: Apple Inc. “The Swift Programming Language” iBooks. https://itunes.apple.com/jp/book/swift-programming-language/id881256329?mt=11