[swift-evolution] Remove Failable Initializers
James Campbell
james at supmenow.com
Wed Mar 9 14:28:22 CST 2016
Yes I understand but I was still able to miss the fact a variable imported
from objective C as a !.
Take this example:
//Imported From Obj-C Library
typealias MyClosure = (value: NSObject!) -> Void
func loadData(block: MyClosure)
//Implemented In Swift File else where
loadData {
value in
print(value) //Crashes if we try to access it
}
This would be clearer to me:
//Imported From Obj-C Library
typealias MyClosure = (value: NSObject!) -> Void
func loadData(block: MyClosure)
//Implemented In Swift File else where
loadData {
//Since the property is a unwrapped optional, the compiler enforces us to
use the ! after the variable name
value! in
print(value!) //Still crashes if we try to access it but at least we know
its an un-wrapped type.
}
This has happened to me a few times with Librarys in Objective-C and I have
released an app that crashed because of that reason.
*___________________________________*
*James⎥Head of Trolls*
*james at supmenow.com <james at supmenow.com>⎥supmenow.com <http://supmenow.com>*
*Sup*
*Runway East *
*10 Finsbury Square*
*London*
* EC2A 1AF *
On Wed, Mar 9, 2016 at 8:23 PM, Brent Royal-Gordon <brent at architechies.com>
wrote:
> > I would love to take a page out of Ruby's book which has ! for things
> that are dangerous and ? for boolean expression. Instead for Swift we could
> have ? for optional returns and ! for forced unwrapped.
> >
> > So we would have:
> >
> > Object()
> > OptionalObject?()
> >
> > value
> > optionalValue?
> > forcedUnwrappedValue!
> >
> > function()
> > optionalFunction?()
> > forcedUnwrappedValue!()
> >
> > optionalProtocolMethod?()
> > forcedProtocolMethod!()
>
> You do understand that `?` at the end of a symbol already means something
> else, don't you? That's how optional chaining works.
>
> --
> Brent Royal-Gordon
> Architechies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160309/f182c40f/attachment.html>
More information about the swift-evolution
mailing list