Last active
August 29, 2015 14:04
-
-
Save bjhomer/b0345c44dfbdb8cb7398 to your computer and use it in GitHub Desktop.
Nil-fallback operator suggestions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Looking for a Swift replacement for the following ObjC code: | |
// id x = foo ?: bar | |
// | |
// Which of the following do you like, if any? Any other suggestions? | |
// (Note that '?' cannot be used in a custom operator.) | |
x = foo !|| bar | |
x = foo |< bar | |
x = foo ||< bar | |
x = foo <|| bar | |
x = foo <| bar | |
x = foo <= bar | |
x = foo <- bar | |
x = foo ||| bar |
I really think there should be an !
in the operator. It helps to hint that there is (or at least could be) an optional unwrapping occurring. Maybe something like !=
.
I'm not sure the operator should be doing an unwrap; it should leave the type of the lhs exactly as it was. After all, since the RHS may be an optional as well, there is no guarantee that the return value of this operator is a non-Optional type.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can't use
:
in an operator either. Otherwise I'd say!:
.