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.
45 lines
1.3 KiB
Swift
45 lines
1.3 KiB
Swift
|
|
extension Promise: CustomStringConvertible {
|
|
/// - Returns: A description of the state of this promise.
|
|
public var description: String {
|
|
switch result {
|
|
case nil:
|
|
return "Promise(…\(T.self))"
|
|
case .rejected(let error)?:
|
|
return "Promise(\(error))"
|
|
case .fulfilled(let value)?:
|
|
return "Promise(\(value))"
|
|
}
|
|
}
|
|
}
|
|
|
|
extension Promise: CustomDebugStringConvertible {
|
|
/// - Returns: A debug-friendly description of the state of this promise.
|
|
public var debugDescription: String {
|
|
switch box.inspect() {
|
|
case .pending(let handlers):
|
|
return "Promise<\(T.self)>.pending(handlers: \(handlers.bodies.count))"
|
|
case .resolved(.rejected(let error)):
|
|
return "Promise<\(T.self)>.rejected(\(type(of: error)).\(error))"
|
|
case .resolved(.fulfilled(let value)):
|
|
return "Promise<\(T.self)>.fulfilled(\(value))"
|
|
}
|
|
}
|
|
}
|
|
|
|
#if !SWIFT_PACKAGE
|
|
extension AnyPromise {
|
|
/// - Returns: A description of the state of this promise.
|
|
override open var description: String {
|
|
switch box.inspect() {
|
|
case .pending:
|
|
return "AnyPromise(…)"
|
|
case .resolved(let obj?):
|
|
return "AnyPromise(\(obj))"
|
|
case .resolved(nil):
|
|
return "AnyPromise(nil)"
|
|
}
|
|
}
|
|
}
|
|
#endif
|