• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Nil Coalescing and Optional Chaining?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: Weird crash in -[NSSearchField setRecentSearches:]
  • Next by Date: Re: Nil Coalescing and Optional Chaining?
  • Previous by thread: Re: Weak linking
  • Next by thread: Re: Nil Coalescing and Optional Chaining?
  • Index(es):
    • Date
    • Thread