Question regarding Swift 2.1 in Xcode 7.
I have declared an optional variable like this:
var something: Int64?
I would like to later assign it to a dictionary key using a shorthand if, like this:
dictionary['something'] = (something != nil) ? something! : nil
XCode is giving me the following validation error:
Result values in '? :' expression have mismatching types: 'Int64' and '_'
What is the issue here? Why can't optional Int64 be nil?
dictionary
type? – Threephase'something'
is not a string, whereas"something"
is. – KnossosAny
instead ofAnyObject
; the prior can hold also value types (e.g. Int64). – Knossos