Answer the question
In order to leave comments, you need to log in
Problem when creating a dictionary with an optional value, why is that?
Hello!
I recently started learning Swift and the following question arose.
Let's say I created a dictionary alias:
typealias Dict = [String:(alpha:Character,num:Int)?]
var dicOne: Dict = ["Key" : ( "V", 1)?]
var dicOne: Dict = ["Key" : ( "V", 1)]
Answer the question
In order to leave comments, you need to log in
Are you confusing the concepts Type and Object of this type
typealias Dict = [String:(alpha:Character,num:Int)?]
(alpha:Character,num:Int)? - here you declare a type, an optional tuple,
and in this line
var dicOne: Dict = ["Key" : ( "V", 1)?]
( "V", 1) is an object with data that will be wrapped in an optional
, the same only on a simpler example
var str:String? = "hello world"
you should open the documentation and see what the optional is
https://medium.com/ios-os-x-development/swift-opti...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question