Giter Club home page Giter Club logo

bolts-swift's People

Contributors

ceyhun avatar ermik avatar facebook-github-bot avatar hcanzonetta avatar heeaad avatar lukas-stuehrk avatar mmtootmm avatar nlutsenko avatar richardjrossiii avatar sapzildj avatar sebleclerc avatar sjorsvb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bolts-swift's Issues

UIWebView deprecated

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!

Chaining tasks of different types

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.

Task never completes

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.

Swift 3.0 Support

This is not working with the XCode 8.0 & Swift 3.0. Its not compiling with Swift 3.0.

Task as rx observable

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

How to bring persistence

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.

continueOnError issue

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>

Difference between continueWith and continueWithTask not clear in the documentation

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?

Swift 5.2 Support?

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

Error in the examples for continueOnSuccessWith?

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

Bolts-Swift over Bolts-ObjC

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)?

Casting to Task without specifying generic type

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?

Value of type 'BFTask<AnyObject>' has no member 'continueOnSuccessWith'

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).

Continue block not executing for success case

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
})

using Bolts with Parse Queries

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

Bolts Swift macOS Compiler Error in Xcode 10

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

Screenshot:
error

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?

How to know which task fails in chain of tasks?

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 {
                //
            }
        }

7 Semanic Issues on XCode 10.1

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

Swift 4 update

Hi, @nlutsenko. Are you planning to deploy an update for swift4? Have some troubles and getting a swift compile error.

pod install fetches incorrect files...

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?

Xcode 9 - "Task" error

I just upgraded Xcode, now with Swift 4 and an error has occurred at the Task swift file! See picture below:

screenshot at sep 23 15-09-58

It seems the success case needs an argument...
Have in mind I already have upgraded the SDK with cocoapods.

Thanks in advance!

Bumping the podspec version

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.

Swift 3 - 133 Issues

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 ?

Use of undeclared type 'Task'

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?

Implement new set of continuations for error-only use case.

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>

Task closure continueOnSuccessWith executes when task is pending

screen shot 2016-06-01 at 15 23 28

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?

            })

Version convention

Hi
I'm wondering why don't you bump version after merge into dev? When can I get a "build" with latest changes?

Enabling local datastore causes constant PFConsistencyAssert

(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 TaskCompletionSources 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! 🤓👍

Deprecated API Usage: UIWebView

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.

whenAny task is comleted with success even if all tasks are completed with 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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.