2

I'm trying to cascade a promise through some classes which add functionality at each level.

+ (AnyPromise *) method {
    return [SomeClass whichReturnsPromise]
    .then(^(id obj){
        // do stuff
        return obj;
    });
  }

Unfortunately this code is throwing an error on the second line:

exc_bad_access (code=1 address=0x10)

(Note: just calling return [SomeClass whichReturnsPromise] works fine)

I've scoured stackoverflow answers and tried many variations of the above code (which would work in javascript), but I keep getting the same error. How do I fix this?

smileham
  • 1,430
  • 2
  • 16
  • 28

2 Answers2

2

Turns out a break case for [SomeClass which ReturnsPromise] was returning nil from before it was converted to return a promise. Changed it to return a promise with value nil. Works now.

smileham
  • 1,430
  • 2
  • 16
  • 28
0

Without testing, I think the following should work:

[self wait].then(^{
   return [SomeClass whichReturnsPromise];
}).then(^(id obj) {
   return obj;
});

I know the following is Swift, but if you have an AnyPromise you can use it in a Promise<T> chain:

someSwiftPromise().then { _ -> AnyPromise in
   // provided by `pod PromiseKit/SystemConfiguration`
   return SCNetworkReachability()
}.then { (obj: AnyObject?) in
   // AnyPromise always resolves with `AnyObject?`
}
gotnull
  • 26,454
  • 22
  • 137
  • 203