Optional<T> has a map method.
/// If `self == nil`, returns `nil`. Otherwise, returns `f(self!)`. func map<U>(f: (T) -> U) -> U?
When do we want to convert Int? in UInt64? , we can:
let iVal:Int? = 42 let i64Val = iVal.map { UInt64($0) }
Instead:
var i64Val:UInt64? if let iVal = iVal { i64Val = UInt64(iVal) }
Here ImplicitlyUnwrappedOptional<T> has the same method:
/// If `self == nil`, returns `nil`. Otherwise, returns `f(self!)`. func map<U>(f: (T) -> U) -> U!
So, I tried ... and could not: (
let iVal:Int! = 42 let i64Val = iVal.map { UInt64($0) } // ^ ~~~ [!] error: 'Int' does not have a member named 'map'
Here is the question: How can I call this method?
source share