Re: Nil Coalescing and Optional Chaining?
Re: Nil Coalescing and Optional Chaining?
- Subject: Re: Nil Coalescing and Optional Chaining?
- From: Charles Jenkins <email@hidden>
- Date: Fri, 07 Nov 2014 09:36:45 -0500
Well, if you have only one argument, then arguments.count would be 1, but to get the argument, you’d ask for Process.arguments[0]. Arrays are zero-based.
—
Charles Jenkins
On Friday, November 7, 2014 at 09:30, David Wood wrote:
> (Dagnabbed mailing list didn’t set the ReplyTo field! What’s up with that?)
>
> > On Nov 7, 2014, at 8:57 AM, Charles Jenkins <email@hidden (mailto:email@hidden)> wrote:
> >
> > It looks to me like Process.arguments[] does not return an optional value. I think you need to find out how many elements are in the array before attempting to access them by an index.
> >
> > —
> >
> > Charles Jenkins
>
> Sadly, that’s what I gather too. So it looks like there’s no way to work an array subscript into an optional chain, for safeguarding purposes.
>
> Strangely, this new construction also fails, and for the same reason too:
>
> var inputValue = (Process.arguments.count > 0) ? Process.arguments[1].toInt()! : defaultValue
>
> “fatal error: Array index out of range”
>
> I’m running it now from inside XCode, so there are no arguments; would that be a problem?
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden (mailto: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 (http://lists.apple.com)
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden (mailto:email@hidden)
_______________________________________________
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