Skip to content
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

add nullable qualifier to return types that can be nil, to support Swift 2 try-catch syntax #1712

Merged
merged 1 commit into from
Jul 6, 2016

Conversation

dkharrat
Copy link
Contributor

@dkharrat dkharrat commented Jun 24, 2016

This change adds the nullable qualifier to return types of Objective-C methods that can return a nil due to errors. This change makes these methods compatible with the Swift 2 try-catch syntax. In other words, before the change, you had to do this:

let error: NSError?
let msg = Message2(data, error: &error)
if (error != nil) {
    // handle error
} else {
    // use msg
}

After the change, you can use the try-catch syntax in Swift 2:

do {
    let msg = try Message2(data)
    // use msg 
} catch (let error as NSError) {
    // handle error
}

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok to test.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@dkharrat
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@dkharrat dkharrat changed the title add nullable qualifier to nil return types add nullable qualifier to return types that can be nil, to support Swift 2 try-catch syntax Jun 24, 2016
@thomasvl thomasvl self-assigned this Jun 28, 2016
@@ -137,7 +137,7 @@ CF_EXTERN_C_END
/// reason if the data can not be parsed.
///
/// @return A new instance of the class messaged.
+ (instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input
+ (nullable instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix the indent on these so the colons still all line up?

Add the `nullable` qualifier to return types of Objective-C methods that
can return a nil due to errors. This change makes these methods
compatible with the Swift 2 try-catch syntax.
@dkharrat
Copy link
Contributor Author

dkharrat commented Jul 6, 2016

@thomasvl sure, I've pushed the branch with the indentation fixed.

@thomasvl
Copy link
Contributor

thomasvl commented Jul 6, 2016

Thanks and thanks for the patch!

@thomasvl thomasvl merged commit ec45897 into protocolbuffers:master Jul 6, 2016
jcanizales added a commit to jcanizales/grpc that referenced this pull request Jul 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants