Originally created by @PaulWoodIII on GitHub (Jan 17, 2016).
Looking at the code the SaveResult seems a little off
Here why is the save result optional?
```
public static func beginSynchronous(closure: (transaction: SynchronousDataTransaction) -> Void) -> SaveResult? {
return self.defaultStack.beginSynchronous(closure)
}
```
Your implementation always returns a result from what I can see.
Also you might be inspired by Alamofire's Result enum: isSuccess and isFailure can be helpful to some:
https://github.com/Alamofire/Alamofire/blob/990fded98afe5135dc418e1f6eb0287027dd067f/Source/Result.swift
adam
added the question label 2025-12-29 18:21:42 +01:00
@JohnEstropia commented on GitHub (Jan 18, 2016):
@PaulWoodIII The documentation for `beginSynchronous(...)` explains why it's optional:
``` swift
/**
...
- returns: a `SaveResult` value indicating success or failure, or `nil` if the transaction was not committed synchronously
*/
```
So if you don't call `commit()` inside the transaction block (i.e. if you abandon/cancel the transaction), you are guaranteed to get a `nil` result.
As for Alamofire's isSuccess and isFailure, `SaveResult` already implements `BooleanType`, so you are free to check the result as so:
``` swift
transaction.commit { result in
if result {
// ... succeeded
}
else {
// ... failed
}
}
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @PaulWoodIII on GitHub (Jan 17, 2016).
Looking at the code the SaveResult seems a little off
Here why is the save result optional?
Your implementation always returns a result from what I can see.
Also you might be inspired by Alamofire's Result enum: isSuccess and isFailure can be helpful to some:
https://github.com/Alamofire/Alamofire/blob/990fded98afe5135dc418e1f6eb0287027dd067f/Source/Result.swift
@JohnEstropia commented on GitHub (Jan 18, 2016):
@PaulWoodIII The documentation for
beginSynchronous(...)explains why it's optional:So if you don't call
commit()inside the transaction block (i.e. if you abandon/cancel the transaction), you are guaranteed to get anilresult.As for Alamofire's isSuccess and isFailure,
SaveResultalready implementsBooleanType, so you are free to check the result as so:@PaulWoodIII commented on GitHub (Jan 18, 2016):
Okay I get it now the extra code there really helps as well