mxcl / PromiseKit

Promises for Swift & ObjC.
MIT License
14.24k stars 1.46k forks source link

promiseWithBooleanAdapterBlock #1325

Closed yunjinghui123 closed 1 year ago

yunjinghui123 commented 1 year ago

image

promiseWithBooleanAdapterBlock adapter(YES) ,but then value is NO, why?

Xcode15

PromiseKit8.1.1

RomanPodymov commented 1 year ago

Hello @yunjinghui123 In your example v is not BOOL, it's id. Just change argument type in your example.

yunjinghui123 commented 1 year ago

Hello @yunjinghui123 In your example v is not BOOL, it's id. Just change argument type in your example.

Thank you

mxcl commented 1 year ago

it's a bug based on our docs. I don't remember this function, did you add it @RomanPodymov ?

RomanPodymov commented 1 year ago

it's a bug based on our docs. I don't remember this function, did you add it @RomanPodymov ?

Hello @mxcl I also don't remember this function, but I think I explained @yunjinghui123 what is wrong. @yunjinghui123 can we close the issue?

mxcl commented 1 year ago

I guess I added it years ago for some reason.

It should work like the other then() and automatically convert from id to BOOL based on the provided args, but at this point I think we can all agree this “bug” is working as intended.

RomanPodymov commented 1 year ago

Hello @mxcl As I can see promiseWithBooleanAdapterBlock uses [NSNumber numberWithBool:] because AnyPromise uses id for value.

RomanPodymov commented 1 year ago

@yunjinghui123 So you can use NSNumber in your example

void (^fetch)(PMKBooleanAdapter) = ^(PMKBooleanAdapter block){
    block(YES, nil);
};
[AnyPromise promiseWithBooleanAdapterBlock:fetch].then(^(NSNumber* obj){
    XCTAssertEqualObjects(obj, @YES);
});
yunjinghui123 commented 1 year ago

fetch

I will use it this way.Thank you!