Our existing hack broke the new Xcode build system (see #724).
Also, CocoaPods 1.4 didn’t like it.
So I had to rewrite with composition instead adding additional methods via an objc category.
The cause of the issue was that the framework required that the -Swift.h file be generated before the objc portions were built (since the objc extended the swift portion), and neither build system guarantees this.
All tests pass. However it is not as efficient as before. Could use some optimizations.
Having to specialize your thens makes using PromiseKit much less pleasant.
However naming our functions more verbosely, for example:
CLLocationManager.promiseLocations()
// versus
CLLocationManager.promiseLocation()
Read confusingly. This new idea allows promises to be non-ambiguous yet
specialization is easy. For example:
NSURLSession.GET(url).then { data in } // no compiler ambiguity!
// or:
NSURLSession.GET(url).asImage().then { image in }
Since ErrorType is not (necessarily) an NSObject we needed to handle the unhandled tokens differently.
Instead we keep an ErrorConsumptionToken with the ErrorType and ensure we pass it around with subsequent promises.
This appears to work for all possible Swift paths and thus I think it will work for all ObjC paths too and it may be worth switching to this system.
The reason the other system was used (add a runtime iVar) is so that errors that are consumed but then end up going back into the a chain are known to already be consumed. However with further realization it is apparent that any error that goes back into a chain is unconsumed and thus the new system should be work well in all cases.