Avatar
swiftbot BOT 5/16/2018 3:56 AM
Author icon
t.ae
import Foundation let date = Date() let timeZone = TimeZone(secondsFromGMT: 0)! let cal = Calendar(identifier: .gregorian) let comp = cal.dateComponents(in: timeZone, from: date) print(comp.second) print(comp.nanosecond)
Version:
swift-4.1.1-RELEASE
Output:
Optional(14) nil
Error:
/usercode/main.swift:7:7: warning: expression implicitly coerced from 'Int?' to Any print(comp.second) ^~~~~~~~~~~ /usercode/main.swift:7:12: note: provide a default value to avoid this warning print(comp.second) ~~~~~^~~~~~ ?? <#default value#> /usercode/main.swift:7:12: note: force-unwrap the value to avoid this warning print(comp.second) ~~~~~^~~~~~ ! /usercode/main.swift:7:12: note: explicitly cast to Any with 'as Any' to silence this warning print(comp.second) ~~~~~^~~~~~ as Any /usercode/main.swift:8:7: warning: expression implicitly coerced from 'Int?' to Any print(comp.nanosecond) ^~~~~~~~~~~~~~~ /usercode/main.swift:8:12: note: provide a default value to avoid this warning print(comp.nanosecond) ~~~~~^~~~~~~~~~ ?? <#default value#> /usercode/main.swift:8:12: note: force-unwrap the value to avoid this warning print(comp.nanosecond) ~~~~~^~~~~~~~~~ ...
3:56 AM