[swift-evolution] [swift-evolution-announce] [Accepted] SE-0140: Bridge Optional As Its Payload Or NSNull

Jean-Daniel dev at xenonium.com
Tue Sep 13 15:39:15 CDT 2016

> Le 13 sept. 2016 à 01:48, Greg Parker via swift-evolution <swift-evolution at swift.org> a écrit :
>> On Sep 12, 2016, at 3:39 PM, Douglas Gregor <dgregor at apple.com <mailto:dgregor at apple.com>> wrote:
>> As an amendment to SE-0140, Swift will produce a warning when an optional value is converted to a value of type Any, e.g.,
>> 	MyClass().doSomething(stringOpt)  // warning: optional value of type ‘String?’ is converted to an ‘Any’
>> 					  // note: use ‘!’ to force-unwrap the optional
>> 					  // note: use ‘??’ to provide a default value if the optional is nil
>> 					  // note: use ‘as Any’ to silence this warning
>> Such a warning will address most accidental injections of optional values into Any, and the core team felt that this addresses accidental boxing of optional values better than leaving the opaque object types to fail fast in Objective-C code that inspects them (e.g., see this message <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160905/026961.html> for a negative review partly on these grounds).
> Is there a recommended pattern for defining a callee that actually wants to accept anything including optionals with no warning for the caller? 

A function that accept anything (including nil) shouldn’t be declared as nonnull. If I understand correctly, it should be enough to avoid warning.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160913/01009a6c/attachment.html>

More information about the swift-evolution mailing list