Yep, but no one stop you if you pass optional value. And in runtime it crash in 
case if it really will be `nil`. But from other side non-optional params make 
the same, and does not let you pass an optional value, and show error on 
compile time. This make your code more safety.
Now force unwrapped params in function used only if you use old Obj-C code 
without nullability modifiers, so no sense, i think, for clear swift code.

> This confused me at the beginning.
> 
> But doesn't Int! In parameter type means the function is awaiting an 
> unwrapped value so the user should ensure that it data parameter is 
> available, valid, and unwrapped?
> 
> --
> J. Charles
> 
> > Le 8 juin 2016 à 13:30, Spromicky via 
> > swift-evolution<swift-evolution@swift.org>a écrit :
> > 
> > Hello, everyone!
> > 
> > I wanna propose to you to remove force unwrapping in fuction signature for 
> > swift code. That no sense in clear swift code. If we wanna use some 
> > optional value as function param, that is not optional, we must unwrap it 
> > before function call.
> > People who new in swift look at how they old Obj-C code (without 
> > nullability modifiers) translate in to swift:
> > 
> > Obj-C:
> > - (void)foo:(NSInteger)bar {
> > //...
> > }
> > 
> > Swift transaliton:
> > func foo(bar: Int!) {
> > //...
> > }
> > 
> > And think that force unwrapping in signature is good practice. And start 
> > write functions in clear swift code like this:
> > 
> > func newFoo(bar: Int!) {
> > //...
> > }
> > 
> > and use it like this:
> > 
> > let bar: Int? = 1
> > newFoo(bar)
> > 
> > And it really work, and they does not think that this can crash in case if 
> > `bar` will be `nil`.
> > But in clear swift we wanna work with parametrs in function that clearly or 
> > optional, or not.
> > 
> > func newFoo(bar: Int) {
> > //...
> > }
> > 
> > or
> > 
> > func newFoo(bar: Int?) {
> > //...
> > }
> > 
> > When we write a new function we know what we need in this case and use 
> > optional params or not.
> > 
> > So my proposal is remove force unwrapping(`!`) from function signatures, 
> > cause it have no sense, and that confuse new users.
> > _______________________________________________
> > swift-evolution mailing list
> > swift-evolution@swift.org
> > https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> 
> 
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to