-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modest Swift 5.1 updates needed #314
Comments
I am not sure avoiding explicit e.g.
but
or
but
In my opinion, that's the best for readability. I am reluctant to omit a keyword just because it doesn't have to be there. |
This is not a useful example, in my opinion, because you wouldn't often write that in a real program. While the second example is not new; we've always been allowed to drop |
I think we also need to clarify, when writing a SwiftUI Button(action: buttonPressed) {
Text("Hello!")
.padding()
}.padding() vs Button(action: buttonPressed) {
Text("Hello!")
.padding()
}
.padding() Likewise, I'd suggest we advise to always split button actions into specific methods, so they don't clutter the There should probably be a lot more SwiftUI specific standards. |
@marinbenc tell me more about your feeling on splitting button actions into specific methods. The idiom seems to be to put a closure there, but that will flag with SwiftLint with the raywenderlich.com ruleset. Doing as you suggest gets rid of the flagging, which is good. But I hesitate to make that a style guide requirement. Oh, and the second form you show above is the correct form. The first will flag. |
@rcritz @marinbenc Hi! Multiple trailing closure syntax is coming in Swift 5.3 which will undoubtedly be released during WWDC20. I think it will look something like this: Button {
Text("Hello!").padding()
} action: {
print("Hello tapped!")
}
.padding() Notably, this has been added to the API Design Guidelines:
See: https://github.com/apple/swift-evolution/blob/master/proposals/0279-multiple-trailing-closures.md |
I agree that probably moving functions out of |
I disagree with excluding return word. Understanding is preferable that minimalism! |
These come to mind:
Single expressions of return should elide the
return
keyword. I think this keeps with the spirit of minimalism in the current guide and is what the Swift Apprentice and Swift Algorithms books have adopted in the coming new editions.We should probably solicit feedback from the SwiftUI book authors for best practices on formatting body function builders.
Prefer use of
Self
instead of the explicit name of the type when possible.The text was updated successfully, but these errors were encountered: