Nil Coalescing and Optional Chaining?
Nil Coalescing and Optional Chaining?
- Subject: Nil Coalescing and Optional Chaining?
- From: David Wood <email@hidden>
- Date: Fri, 07 Nov 2014 08:34:35 -0500
I'm just trying to cut my teeth on Swift here, and there are a few command-line activities I like to use to make sure I understand what a language is doing.
The goal in this case is to take a parameter from the command line, that may or may not have been entered with the command that started the program, and assign it to a variable for use.
The "Nil Coalescing" operator (??) like the perfect construction:
var inputValue = Process.arguments[1].toInt() ?? defaultValue
And the preprocessor thought it looked good too.
But at runtime, Xcode reports a "Fatal error: Array index out of range."
Is this a bug in the preprocessor (for not flagging something that may not exist), the language itself (for failing to branch upon finding a non-existent value) or my understanding of the capabilities of the language (for trying to get it to do too much)?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden