optional-variables

What the difference between using or not using “!” in Swift?

牧云@^-^@ 提交于 2019-12-04 16:40:41
The ! mark is used for the optional value in Swift to extract the wrapped value of it, but the value can be extracted without the ! : var optionalString: String? = "optionalString" println(optionalString) another example using the ! : var optionalString: String? = "optionalString" println(optionalString!) both the codes above get the right value, so I wonder what's the difference between using and not using ! , is it just for detect an error at runtime if the optional value is nil or something else? Thanks in advance. As others have already stated, a really good place to start would be with

VB.NET := Operator

北慕城南 提交于 2019-11-29 10:24:44
What does the following mean? Class.Function(variable := 1 + 1) What is this operator called, and what does it do? It is used to assign optional variables, without assigning the previous ones. sub test(optional a as string = "", optional b as string = "") msgbox(a & b) end sub you can now do test(b:= "blaat") 'in stead of test("", "blaat") It assigns the optional parameter "variable" the value 2. VB.NET supports this syntax for named (optional) parameters in method calls. This particular syntax informs Class.Function that its parameter variable is to be set to 2 (1 + 1). 来源: https:/

VB.NET := Operator

佐手、 提交于 2019-11-28 03:34:15
问题 What does the following mean? Class.Function(variable := 1 + 1) What is this operator called, and what does it do? 回答1: It is used to assign optional variables, without assigning the previous ones. sub test(optional a as string = "", optional b as string = "") msgbox(a & b) end sub you can now do test(b:= "blaat") 'in stead of test("", "blaat") 回答2: It assigns the optional parameter "variable" the value 2. 回答3: VB.NET supports this syntax for named (optional) parameters in method calls. This

Global variable and optional binding in Swift

橙三吉。 提交于 2019-11-27 09:54:14
I have some quite simple doubt regarding optional binding,global variable & wrapping and unwrapping . Since I am new to SWIFT, its very important to understand the tits & bits of their concepts. 1) In Swift if I declare a global variable, I have 2 options either to make it optional or non optional, so let I am having 2-4 or more optional variables . So is it advisable to optional bind all those variables in viewDidLoad() method// so that I could use them without any problem of unwrapping and fatal error in my program. 2) Let me make myself more clear by the following example- I have 2 VC in my

Downcasting optionals in Swift: as? Type, or as! Type?

谁说胖子不能爱 提交于 2019-11-27 02:45:25
Given the following in Swift: var optionalString: String? let dict = NSDictionary() What is the practical difference between the following two statements: optionalString = dict.objectForKey("SomeKey") as? String vs optionalString = dict.objectForKey("SomeKey") as! String? The practical difference is this: var optionalString = dict["SomeKey"] as? String optionalString will be a variable of type String? . If the underlying type is something other than a String this will harmlessly just assign nil to the optional. var optionalString = dict["SomeKey"] as! String? This says, I know this thing is a

Downcasting optionals in Swift: as? Type, or as! Type?

若如初见. 提交于 2019-11-26 17:29:47
问题 Given the following in Swift: var optionalString: String? let dict = NSDictionary() What is the practical difference between the following two statements: optionalString = dict.objectForKey("SomeKey") as? String vs optionalString = dict.objectForKey("SomeKey") as! String? 回答1: The practical difference is this: var optionalString = dict["SomeKey"] as? String optionalString will be a variable of type String? . If the underlying type is something other than a String this will harmlessly just

Global variable and optional binding in Swift

ぐ巨炮叔叔 提交于 2019-11-26 14:58:49
问题 I have some quite simple doubt regarding optional binding,global variable & wrapping and unwrapping . Since I am new to SWIFT, its very important to understand the tits & bits of their concepts. 1) In Swift if I declare a global variable, I have 2 options either to make it optional or non optional, so let I am having 2-4 or more optional variables . So is it advisable to optional bind all those variables in viewDidLoad() method// so that I could use them without any problem of unwrapping and