-
-
Notifications
You must be signed in to change notification settings - Fork 877
Make all synchronous APIs have 'throws' in Swift 2. #162
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
Conversation
5105efc
to
8bb61ef
Compare
Looks awesome! |
8bb61ef
to
f5f848a
Compare
Thank you for doing this. I will import this branch and try it out. |
I wish to bring your attention the differences between:
and
Both are calls that can fail. Forgiving my lack of experience with your framework's patterns,shouldn't they have the same return type that is nullable to ensure that try-catch functions properly? For example:
Should all synchronous methods using try catch return Anon, |
Thanks for bringing this up! You are absolutely correct, this is our mistake. |
I suspect you should also consider replacing the |
👍 |
Make all synchronous APIs have 'throws' in Swift 2.
Hi, I had a quick question on how to update my xcode 6.4 code to the xcode 7 version. Old code: func a()
item = b()
if item == nil {..}
else {..}
func b() -> PFObject?
let x = PFObject(className: data)
let success = x.save()
if success { return x }
return nil now that save doesn't return a boolean, I am attempting to accomplish the same result with: do {
try x.save()
return x
} catch {
return nil
} Is this the proper syntax / intended method? |
@anthony-lai, yes that is correct syntax. func b() -> PFObject? {
let x = PFObject(className: "Yolo")
do {
try x.save()
return x
} catch let error {
print(error)
return nil
}
} You could also make the function itself throw, so you can propagate the error further. func b() throws -> PFObject {
let x = PFObject(className: "Yolo")
try x.save()
return x
} |
@nlutsenko You can also use swift's |
@nlutsenko @richardjrossiii Thanks! |
(-‸ლ) @richardjrossiii you are right... Absolutely forgot about the optional |
throws
when used from Swift.PF_SWIFT_UNAVAILABLE
, please note that this macro does nothing when compiled with Xcode 6.4, but only works on Xcode 7 (the one that has Swift 2).After change (Swift 2):
Before change (Swift 2):
Before && After Change (Swift 1.2):
closes #152
cc @richardjrossiii