boltsframework / bolts-swift Goto Github PK
View Code? Open in Web Editor NEWBolts is a collection of low-level libraries designed to make developing mobile apps easier.
License: Other
Bolts is a collection of low-level libraries designed to make developing mobile apps easier.
License: Other
Hi, I Installed Bolts-Swift via Podfile:
Xcode Version 8.0 (8A218a)
platform :ios, ’10.0’
use_frameworks!
target 'Bolts' do
pod 'Bolts-Swift'
end
After opening it I have 133 issues ? On the overview page it says that this package supports swift 3? Do I have to enter anything in addition to the pod file in order to make this working ?
Whenever I submit a new build, Apple sends me the following email:
"ITMS-XXXXX: Deprecated API Usage - Apple will stop accepting submissions of app updates that use UIWebView APIs starting from December 2020. See https://developer.apple.com/documentation/uikit/uiwebview for more information."
It looks like Bolts uses the UIWebView to parse HTML. I'm not sure if this is even a smart thing to do, especially given the fact that December is coming up soon.
The continueOnErrorWith(continuation:)
method currently requires that a task returning the same type of result as the receiver be returned in the continuation closure. This makes something like this impossible:
let task: Task<Settings> = getSettingsTask()
let continueTask = task.continueOnSuccessWithTask { (settings: Settings) -> Task<String> in
return self.updateSettingsTask()
}
task.continueOnErrorWith { (error: ErrorType) -> () in <-- compiler error here
self.showError(error)
}
This produces the compiler error Declared closure result '()' is incompatible with contextual type 'Settings'
, because the continueOnErrorWith(continuation:)
method expects the closure to return a Settings
instance. A similar issue arises with the continueOnErrorWithTask(continuation:)
method.
A less than ideal workaround is to do this
task.continueWith { (task: Task<Settings>) -> () in
return
}.continueOnErrorWith { error in
self.showError(error)
}
A proposed fix is to change the method signatures to
public func continueOnErrorWith<S, E: ErrorType>(executor: Executor = .Default, continuation: (E throws -> S)) -> Task<S>
and
public func continueOnErrorWithTask<S, E: ErrorType>(executor: Executor = .Default, continuation: (E throws -> Task<S>)) -> Task<S>
e.g.
(userPathShortened)…"/BoltsSwift-iOS.xcconfig BoltsSwift-iOS.xcconfig line 9: Unable to find included file "Shared/Platform/iOS.xcconfig"
Is this my fault? I haven't touched anything, just opened it.
In below code, continue block is executing only for failure cases but not for success cases.
QMServicesManager().authService.signUpAndLogin(with: user).continue({ (users: BFTask!) -> Any? in
if users.isFaulted || (users.error != nil) {
let alert = UIAlertController(title: "Error!", message: "Some error occurred on server", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
else if users.isCancelled {
let alert = UIAlertController(title: "Error!", message: "User registration is not completed", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
else if users.result != nil {
let alert = UIAlertController(title: "Done!", message: "User (users.result!.fullName) registration is successful", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
return nil
})
Hi all!
Thanks for really helpful lib!
Can anybody help me?
I have chain of 3 tasks ( request to BE) .
Every task/request can return error with code 401 . But I need to know which task failed , because in case 401 I need to perform different steps depending on which task failed.
Code sample:
let verifyTask = interactor.verifySMSCode(verificationID: verification.codeID, code: smsCode)
verifyTask.continueOnSuccessWithTask { token -> Task<LoginResponse> in
self.interactor.saveSMSToken(token: token)
return self.interactor.login(phone: self.user.phoneNumber)
}.continueOnSuccessWithTask { loginResponse -> Task<UserDetails> in
self.interactor.saveAuthData(authData: loginResponse)
return self.interactor.requestUserDetails(userID: loginResponse.userID)
}.continueOnSuccessWith(Executor.mainThread) { [weak self] userDetails in
self?.view.hideActivityIndicator()
self?.interactor.saveUserDetails(userDetails: userDetails)
self?.moduleOutput.didLoginSuccessfuly()
}.continueOnErrorWith(Executor.mainThread) { [weak self] error in
self?.view.hideActivityIndicator()
if (error as NSError).code == 401 {
// every of 3 requests / task can return me error code == 401
// How can I understand which of previous 3 task failed???
}
self?.view.showError(title: nil, message: error.localizedDescription, buttonTitile: "OK")
}
Are there any ways to separate which task are failed in continueOnErrorWith block ??
P.S. I want to use chain of tasks to make code look better.
I don't wont to use :
verifyTask.continueWith { task in
if let result = task.result {
self.interactor.login(phone: user.phoneNumber).continueWith { task in
self.interactor.requestUserDetails(userID: result.userID).continueWith {
if ///
}
}
} else if let err = task.error {
//
}
}
command.execute().continueOnSuccessWith { (commandResult: GRAuthorizationCommandResult) -> Task<GRObserversTransferObject> in
let observersTask: Task<GRObserversTransferObject> = ...
return observersTask
}.continueOnSuccessWith(continuation: { (task: Task<GRObserversTransferObject>) -> Void in
let observers = task.result! // CRASH, task is pending, why?
})
Hi
I'm wondering why don't you bump version after merge into dev? When can I get a "build" with latest changes?
The last podspec version bump was 1.3.0 of last year for Swift 3.0 support. It should be bumped up with changelog for the recent Swift 4.0 changes.
Hello,
I added pod 'Bolts-Swift' to my podfile and build my app. I notice the issues were fixed as per: #64 issue # 64 and if I compare the file on my disk to the one here they are different. When I run pod install it tells me it is Installing Bolts-Swift (1.3.0)
Can someone tell me what I could be doing wrong?
Will Bolts be supporting Swift 5.2?
With new XCode and Carthage i have error of compiling: Module compiled with Swift 5.0 cannot be imported by the Swift 5.2 compiler
I'm trying to create a universal error handler for my application and to make matters even more complicated I'm using an event bus to pass a task around. I'm trying to do the following:
let apiTask = data.object as! Task // Option 1
let apiTask = data.object as! Task<AnyObject> // Option 2
apiTask!.continueWith { (task) in
if(task.cancelled || task.faulted) {
self.isInError = true
} else {
self.isInError = false
}
}
Option 1 gives a compile time error saying the generic type TResut of Task cannot be inferred.
Option 2 causes a runtime error saying Task<SpecificType> cannot be caster to Task<AnyObject>
I have the same implementation in Java where it seems you don't need to specify the generic type so I appreciate this might be a language limitation rather than a library one. TResult
could be potentially any type so I can't specify it in the method above. Is there any way to work around this?
Hi @nlutsenko. Are you planning to add Cancellation Token to current implementation?
Hi.
Could you add Swift Package Manager support?
Best regards,
Vasili Silin.
If there any workaround to run tasks with different result type in parallel?
Task.whenAll([Task(1), Task("two")])
- This won't compile
Semantic issues. When is a release planed?
When your framework compiled with optimizations (try to install via Carthage) assert
is not checked. Therefore this code from the TaskCompletionSource
is never executed:
public func setResult(result: TResult) {
assert(task.trySetState(.Success(result)), "Can not set the result on a completed task.")
}
As Apple mentions:
/// Traditional C-style assert with an optional message.
....
/// * In -O builds (the default for Xcode's Release configuration),
/// `condition` is not evaluated, and there are no effects.
I have used Bolts with Objective-C before but when I installed this (through Cocoapods) I can't seem to use them.
I'm trying to create a Task of my own but when I use the code from the README...
func doSomethingAsync() -> Task<PFObject> {
}
I just get the error "Use of undeclared type 'Task'"
I don't think the README is correct as PFObject
is not found in the entire project.
I can't seem to find an import that works.
Am I doing something wrong?
Is there any approach to convert Task
to Observable
? I'd write:
extension Task {
func asObservable<TResult>() -> Observable<TResult> {
return Observable.create { observer in
self.continueWith { task in
if let result = task.result {
observer.onNext(result)
observer.onCompleted()
} else if let error = task.error {
observer.onError(error)
}
}
return Disposables.create()
}
}
}
It could work if you have a protocol with associated type
I just installed Parse via Cocoapods on Xcode 10. I'm using this Podfile:
def shared
use_frameworks!
pod 'Parse'
pod 'ParseLiveQuery'
end
target 'MyApp Mac' do
shared
end
target 'MyApp iOS' do
shared
end
...and my Mac app files to compile with the error:
Missing argument for parameter #1 in call - Task.swift
I've tried deleting /DerivedData
, cleaning the build folder, removing Podfile caches and reinstalling, and restarting Xcode.
Any ideas of what else I can try?
I have a Swift iOS project that is using the Parse SDK, and was hoping to take advantage of the simplified syntax of the Bolts-Swift project.
Here was my code:
PFCloud.callFunction(inBackground:"patient_getMovements", withParameters:nil).continue(successBlock:
{
task -> Any? in
// ...
}
I added the Bolts-Swift dependency and import statement, and figured I could now do this, as shown in the docs:
PFCloud.callFunction(inBackground:"patient_getMovements", withParameters:nil).continueOnSuccessWith
{
task -> Any? in
// ...
}
But I get the error:
Value of type 'BFTask' has no member 'continueOnSuccessWith'
What am I doing wrong? I'm confused as to what the relationship is between this and the Obj-C Bolts project (which seems to be what my project is still using).
Hi, @nlutsenko. Are you planning to deploy an update for swift4? Have some troubles and getting a swift compile error.
Hi there, thanks for your great job migrating Bolts to swift, this is impressive 👍
I've recently required using Task.whenAny
and faced the problem that the task
is succeeded
even if all tasks from whenAny
array are completed with errors.
@nlutsenko is it expected behavior here?
P.S I've checked the Bolts in Objc and the same method returns error in such case. I'll submit a PR if this is a case?
Will we be seeing swift 4.2 support anytime soon? Thanks
Bolts Group
Semantic Issue Group
/Users/georg/Projekte/Apps/anyfinder/Pods/Bolts/Bolts/iOS/BFAppLinkReturnToRefererController.m:133:17: Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior
/Users/georg/Projekte/Apps/anyfinder/Pods/Bolts/Bolts/iOS/BFAppLinkReturnToRefererController.m:148:18: Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior
/Users/georg/Projekte/Apps/anyfinder/Pods/Bolts/Bolts/iOS/BFAppLinkReturnToRefererController.m:189:13: Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior
/Users/georg/Projekte/Apps/anyfinder/Pods/Bolts/Bolts/iOS/BFAppLinkReturnToRefererController.m:190:40: Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior
/Users/georg/Projekte/Apps/anyfinder/Pods/Bolts/Bolts/iOS/BFAppLinkReturnToRefererController.m:193:24: Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior
/Users/georg/Projekte/Apps/anyfinder/Pods/Bolts/Bolts/iOS/BFAppLinkReturnToRefererController.m:195:9: Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior
/Users/georg/Projekte/Apps/anyfinder/Pods/Bolts/Bolts/iOS/BFAppLinkReturnToRefererController.m:203:17: Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior
(Hello!? Anyone home? 👀)
I've been using Bolts-Swift for a bit but recently enabled the local datastore in the Parse SDK to be able to pin models locally. Now Bolts-Swift is constantly throwing the following assert:
PFConsistencyAssert(existing == nil || existing == object,
@"Attempted to change an objectId to one that's already known to the OfflineStore.");
I'm not quite sure how to work around this. It seemed when I called TaskCompletionSource
s asyncly in a DispatchQueue
, the complaint went away, but this brought other problems so I'd rather not do that.
Any ideas what's going on and how to handle?
Thanks! 🤓👍
oow
Any word on when a Swift 3 update will be released?
According to the readme, continueOnSuccessWith
is used like this:
save(object).continueOnSuccessWith { task in
// The object was saved succesfully
let result = task.result
}
however, when trying to use it it actually takes the task result as parameter to the closure, and not the task itself.
code in Task+ContinueWith.swift
public func continueOnSuccessWith<S>(_ executor: Executor = .default,
continuation: @escaping ((TResult) throws -> S)) -> Task<S> {
And in my own code I have this:
runDataTask(request).continueOnSuccessWith { result in
Hi, I have a swift project and I'm using Parse and Facebook SDK which use Bolts, so since I already have the dependency I decided to use it but I just notice there is a swift version of Bolts. I guess there is a good reason why the frameworks are separated but I’m not sure why.
should I use Bolts-ObjC with swift since I already have it or also add Bolts-swift?
I notice there are some missing features in the swift framework like Applink and cancellationToken, can I still mix these with the swift framework (like BFCancellationToken)?
The docs state:
If you return any object from continueWith
function - this will become a result of the new function. And if you want to call into more tasks and return those results - you can use continueWithTask
. This gives you an ability to chain more asynchronous work together.
For me the difference is absolutely not clear, especially since both have exactly the same signature in Swift.
@discardableResult
public func continueWith<S>(_ executor: Executor = .default, continuation: @escaping ((Task) throws -> S)) -> Task<S> {
vs
@discardableResult
public func continueWithTask<S>(_ executor: Executor = .default, continuation: @escaping ((Task) throws -> Task<S>)) -> Task<S> {
in the source code for continueWith
it states
- returns: A task that will be completed with a result from a given closure.
continueWithTask
has
- returns: A task that will be completed when a task returned from a closure is completed.
Does this mean that the task returned by continueWith
will have a completion/error state as soon as it is returned, while in continueWithTask
it might not immediately be the case?
And in the second case, is the task that will be completed
not simply the task returned by the closure?
Today I submitted an app to TestFlight and received this email:
Dear Developer,
We identified one or more issues with a recent delivery for your app, "Foo Beta" 0.5.9 (111). Your delivery was successful, but you may wish to correct the following issues in your next delivery:
ITMS-90809: Deprecated API Usage - Apple will stop accepting submissions of apps that use UIWebView APIs . See https://developer.apple.com/documentation/uikit/uiwebview for more information.
After you’ve corrected the issues, you can use Xcode or Application Loader to upload a new binary to App Store Connect.
Best regards,
The App Store Team
The app did indeed get submitted to TestFlight successfully where I was able to download the app and use it just fine. However, I would like to avoid having my app rejected in future submissions.
I went into XCode and searched for UIView
and did not find my source code use it anywhere except within Bolts and Facebook Share SDK. I am creating issues in both repositories to bring attention of this deprecation that Apple is now enforcing.
Thanks!
When support for XCode 14.3 will be added ? I can see this library is built with XCode 9.
Hi team,
while building the app with xcode 14.3 I am facing issue with Bolts-swift library.
Is there any update when you guys will be updating configuration of it?
I have tried all kinds of combinations, but it seems impossible to me to chain several tasks (in series) where the tasks have different result types and whereby each task upon error needs to stop the execution of all subsequent tasks. It's compile time error galore for me.
I also think the docs are lacking. They don't really show how to chain multiple tasks using the success/error handlers. The paragraph chaining tasks
doesn't even show how to acutally chain tasks.
Updated mac to developer preview of Sierra and now project wont build instead giving the error on the bolts package saying: error: A cryptographic verification failure has occurred.
Will Bolts-Swift be supporting Swift 5.0 anytime soon ?
How to bring persistence with DB(SQLite or realm etc)?.
Say like i have a Task in which trying to hit one REST API, before making network call i am killing the App. When i reopen the app i wanted my task to be resumed.
This is not working with the XCode 8.0 & Swift 3.0. Its not compiling with Swift 3.0.
func findAsync(query:PFQuery<PFObject>) -> BFTask<[PFObject]> {
let task = BFTaskCompletionSource<[PFObject]>()
query.findObjectsInBackground { (results:[PFObject]?, error:Error?) in
if (error == nil) {
task.setResult(results!)
} else {
task.setError(error!)
}
}
return task.task
}
unfortunately, the above code throws the error
Type [PFObject] does not conform to protocol for 'AnyObject'
however, I need to type as [PFObject] to put the results of the query as the result to the task.
how do I accomplish this in Swift 3?
i was able to get past the error by using NSArray, however the result for the function never seems to get set, waituntilfinished just hangs.
func findAsync(query:PFQuery<PFObject>) -> BFTask<NSArray> {
let task = BFTaskCompletionSource<[NSArray]>()
query.findObjectsInBackground { (results:[PFObject]?, error:Error?) in
if (error == nil) {
task.setResult(NSArray.init(results!))
print(task.task.result!) // at this point i can verify that the result appears to be the desired
} else {
task.setError(error!)
}
}
return task.task
}
but calling the function with self.findAsync() with a query i know returns data, just simply returns nil or an uncompleted task
We have continueWith
and continueOnSuccessWith
, but we don't have continueOnError
, which would be very helpful for explicit error handling.
This issue is for implementing an enhancement on Task
with 2 new methods:
continueOnErrorWith<T>(executor: Executor = .Default, continuation: (ErrorType -> T throws)) -> Task<T>
continueOnErrorWithTask<T>(executor: Executor = .Default, continuation: (ErrorType -> Task<T> throws)) -> Task<T>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.