Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Gabriel Montague
    @montaguegabe
    Hi all, how can I use PromiseKit 7 in my project? Is there an option to do so through CocoaPods?
    Štembera Michal
    @stemberamichal

    Hello @montaguegabe , I hope It won't mind if I answer as this is a common CocoaPods question mostly.

    PromiseKit 7 Alpha
    We are testing PromiseKit 7 alpha, it is Swift 5 only. It is tagged and thus importable in all package managers.

    According to CocoaPods for bleeding edge uses you can specify url and tag:

    pod 'PromiseKit', :git => 'https://github.com/mxcl/PromiseKit.git', :tag => '7.0.0-alpha3'
    Štembera Michal
    @stemberamichal

    Hi @mainaaw what are you probably looking for is Promise<T>.pending()

    In your case you can use it as follows (PromiseKit 4 unfortunately - adjust in newer versions):

    typealias Thunk = () -> Void
    func foo() -> (Thunk, Promise) {
        let pending = Promise<[String: Any]>.pending()
        return  (
            { ... pending.fulfill() ... },
            pending.promise
        )
    }
    Gabriel Montague
    @montaguegabe
    @stemberamichal thank you very much! Sorry to bother you with such a simple question; I thought in here I had read someone say you had to clone the repo
    Štembera Michal
    @stemberamichal
    @montaguegabe Don't worry, I just wondered by in search for answer to my own question. Glad I could help :)
    Gary Hooper
    @garyhooper
    Trying to test PromiseKit 7, I get an error with cocoapods: "Unable to find a specification for 'PromiseKit'." What is the most straightforward way to install it? Can you create a cocoapods spec file for v7?
    Gabriel Montague
    @montaguegabe
    I couldn't find any cocoapods spec file either. But you can get it working by cloning the repo, building for "Generic iOS Device", copying the framework into your project, then making sure it also in the "Embed Frameworks" section
    Gabriel Montague
    @montaguegabe
    Any pointers on how to get this working with CoreLocation extension would be greatly appreciated. – Or are all the extensions Objective C and thus now unusable?
    Tony1120
    @Tony1120
    hi
    Does anyone know how to get the "didsentbodydata" delegation method work with the promise kit? I have datatask in my promise chain but the delegation method is never called
    Nitish Sachar
    @uioporqwerty
    For PromiseKit 6, how do you take multiple arrays of type [Promise<Int>] and resolve them all at once? when(fulfilled: promiseArr1, promiseArr2...) throws this error Global function 'when(fulfilled:_:)' requires that '[Promise<Int>]' conform to 'Thenable'
    Max Howell
    @mxcl
    @uioporqwerty when(fulfilled: promiseArr1 + promiseArr2)
    @Tony1120 impossible to help with so little context
    qazi1002
    @qazi1002
    Hi anyone here to help?
    Max Howell
    @mxcl
    @qazi1002 hi
    Harrison Friia
    @harrisonfriia

    Hello - I’m writing a wrapper for our base API call, which returns a custom error type APIServiceError.
    The wrapper looks like this:

    func send<T: Decodable>(request: Request) -> Promise<T> {
            return Promise { seal in
                let completion: (Swift.Result<T, APIServiceError>) -> Void = { result in
                    switch result {
                    case .success(let data):
                        seal.fulfill(data)
                    case .failure(let error):
                        seal.reject(error)
                    }
                }
                self.send(request: request, completion: completion)
            }
        }

    When I call that wrapper, is it possible for the catch block to return my custom error type rather than Error?

    func foo(request: Request) {
            self.apiClient.send(request: request).done { (result: Session) in
    
            }.catch { (error) in
                // error here is Error, not APIServiceError
            }
        }
    Ric Santos
    @ricsantos
    is APIServiceError a Swift Error?
    if so, you can do this inside the catch:
                switch error {
                case ModelError.objectNotFound:
                        // handle your error case
                default:
                      // handle other errors
                }
    Harrison Friia
    @harrisonfriia
    Yep, specifically a LocalizedError. I'm wondering if the type can be inferred directly so I don't have to do any casting
    Ric Santos
    @ricsantos
    Well it could be an Error, or your APIServiceError, so you will need to check its type...
    Harrison Friia
    @harrisonfriia
    Right, but I want to know if there's a way to get catch to give me an APIServiceError specifically
    Ric Santos
    @ricsantos
    Well you can do that I suppose, when you call seal.reject() only do that if its an APIServiceError. What would you do if it a different error though?
    Ian Manor
    @imvm
    Is there any way to get the results of when(fulfilled:) promises in a map? I want to write something like this:
    func getPromise() -> Promise<SomeObject> {
        when(fulfilled: promiseA, promiseB).map { resultA, resultB in
            doSomething(resultA, resultB)
        }
    }
    
    func doSomething(a: ObjectA, b: ObjectB) { return SomeObject(a, b) }
    I want to avoid having to do this:
    funs getPromise() -> Promise<SomeObject> {
        let promiseA = ...
        let promiseB = ...
    
        when(fulfilled: promiseA, promiseB).map { _ in
            doSomething(promiseA.value!, promiseB.value!)
        }
    }
    
    func doSomething(a: ObjectA, b: ObjectB) { return SomeObject(a, b) }
    Aaron Hilton
    @otri
    I'm having trouble getting the swift compiler to figure this out:
                firstly {
                    return Promise { seal in
                        Purchases.shared.purchaserInfo() { purchaserInfo, error in
                            seal.resolve(purchaserInfo, error)
                        }
                    }
                }
    Gives me a couple errors
    Generic parameter 'T' could not be inferred
    Generic parameter 'U' could not be inferred
    Aaron Hilton
    @otri
    So I'm sad to say, I've switched frameworks.
    I've been battling with PromiseKit's swift compiler errors (and swift's poor error messages) a lot on this project, so ultimately I have switched to Google's Promises framework. So this was a bit surprising, because PromiseKit seems really solid otherwise. I assumed it was my misunderstanding the nature of the framework. However, these ambiguity errors went on and on, forcing re-write and restructuring to work around it, and so on, these issues just wouldn't go away.
    A fundamental thing about PromiseKit that ended up becoming a bit detrimental was how "magic" the type bindings and semantics worked. Without explicit control over typed promises, ambiguity edge cases would crop up. Whereas the Google Promises framework allows a more explicit type binding, and a clearer promise chaining.
    I appreciate the ton of work that went into making an otherwise elegant Promise framework. Just quirks of the swift compiler ruined the party I guess.
    Vinod Reddy
    @vinnuzmobile
    Hello all, Could someone please share me any article about unit testing for using promisekit. Thank you.
    Adam Dahan
    @adamdahan

    Hi can someone help me out?

    I have a function like this:

    func getTradingHours() -> Promise<Bool> {
            return Promise<Bool> { seal in
                let urlString = "some_url"
                let url = URL(string: urlString)!
                let request = URLRequest(url: url)
                self.client.fetch(request, requestDataType: [String: Bool].self) { (result) in
                    switch result {
                    case .success(let hours):
                        guard let isOpen = hours["isTheStockMarketOpen"] else {
                            return
                        }
                        seal.fulfill(isOpen)
                    case .failure(let error):
                        seal.reject(error)
                    }
                }
            }
        }
    and I am trying to use it like so:
     firstly {
                getTradingHours()
            }.then { isOpen in
                print(isOpen)
            }.ensure {
                // something that should happen whatever the outcome
                print("Ensurance")
            }.done {
                // all promises are resolved
                // handle final logic here
                print("done")
            }.catch {
                // handle error here
                print(
            }
    but I keep getting ridiculous errors
    Screen Shot 2021-01-15 at 3.20.36 PM.png
    would love to be pointed in the right direction?
    Ric Santos
    @ricsantos
    In your then, you need to return a promise. The print line isn’t a promise
    Also catch has an error param and the line in it won’t compile
    Fabien Penso
    @penso
    Hi everyone, how do you fix the stack issue when you have bugs, I can't figure how to find the code crashing inside a promise?
    I saw you can use DispatchQueue.default = zalgo but I don't understand what zalgo is, and looking at the source doesn't help
    yashpalslathia21
    @yashpalslathia21
    Is version 6.3.4 supported on iOS 12.5? Getting a crash issue in PromiseKit on iOS 12.5
    ConfusedVorlon
    @ConfusedVorlon

    Hi - I'm new to promise kit - loving it so far
    Is there a .done equvalent which gets rid of the need for a catch?

    My use case is an NSAlert promise. Clicking 'ok' fulfils the promise. Clicking 'cancel' throws an error.

    I don't need to do anything in the error case, and was wondering if there was a shortcut for

    .done {
                    //handle 'ok'
                }
                .catch {_ in }
    Ric Santos
    @ricsantos
    Throw PMKError.cancelled
    Or try .cauterize()
    ConfusedVorlon
    @ConfusedVorlon

    throwing PMKError.cancelled from my promise
    seal.reject(PMKError.cancelled)
    still gives me a 'result of call to done.. is unused'
    Have I misunderstood what you meant?

    .cauterize() does do the job

    thank you!

    ConfusedVorlon
    @ConfusedVorlon

    I have created a promise wrapper for NSAlert. It works on the 'done' path - but the 'cancel' path never fulfils.
    I have checked that seal.reject() is getting called - but this never makes it back to the .catch block.

    Can anyone give me any clues?

    thanks.

    extension NSAlert {
    
        static func alert(_:PMKNamespacer,from window:NSWindow,
                     message:String,
                     informativeText:String? = nil,
                     ok:String = "Ok",
                     cancel:String? = nil) -> Promise<Void> {
    
            return Promise {
                seal in
    
                let alert = NSAlert()
    
                alert.messageText = message
                if let informativeText = informativeText {
                    alert.informativeText = informativeText
                }
    
                alert.addButton(withTitle: ok)
                if let cancel = cancel {
                    alert.addButton(withTitle: cancel)
                }
    
                alert.beginSheetModal(for: window, completionHandler: { returnCode in
                    if returnCode == .alertFirstButtonReturn {
                        seal.fulfill()
                    }
                    else {
                        seal.reject(PMKError.cancelled)
                    }
                })
            }
        }
    }
    and here it is in use:
    clicking 'OK' does call the .done block.
    clicking 'Cancel' does not call the .catch block (or the .done one)
            firstly {
                NSAlert.alert(.promise,from:window,
                              message:"Testing.",
                                                   ok:"Ok",
                                                    cancel:"Cancel")
            }
            .done {
                print("Ok")
            }
            .catch { error in
                print("Cancel")
            }
    ConfusedVorlon
    @ConfusedVorlon
    Ok - and I figured it out. PMKError.cancelled doesn't trigger a callback.
    That seems like a gotcha that should be mentioned...
    Ric Santos
    @rixantos_twitter
    This is expected, PMKError.cancelled is a CancellableError. If an error conforms to CancellableError and isCancelled returns true, the catch block will not be executed.
    If you want some code to execute no matter what button the user taps, add a ensure { } block to your chain before the catch { } block. The code in ensure will execute no matter what the outcome.
    ConfusedVorlon
    @ConfusedVorlon
    Thanks Ric - I did figure this out. To my mind it is an unexpected and barely documented behaviour!
    I have submitted a couple of pull requests on the docs.