On May 29, 2016, at 19:16 , Daryle Walker <[email protected]> wrote:
>
> Since I am using the substring and not including “.SubstringNotRequired”, I
> can just remove the “guard” block, tack on a “!” to substring’s identifier,
> and be done with it, right?
The problem is there’s no API contract that says exactly when (and when not)
the string will be nil. I would suggest, therefore, that you don’t place any
reliance on it not being nil in your use cases, but rather deal with it like
this (at the top of the closure):
let substring = substring ?? ""
That is, shadow the parameter with a non-optional String variable, and assume
an empty string when the parameter is nil. Note that the empty string will be
either a tagged pointer or a shared global constant, so there’s no real
performance issue in doing this. After that, you don’t care whether it was nil
or not.
This is consistent with what would happen in Obj-C if you didn’t check for nil,
since in Obj-C a nil pointer will appear to be an empty string in many contexts.
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]