Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

What sort of syntax in this `[object setSomething:^{ resolve(...) }]` on Objective-C?

$
0
0

I am reverse-engineering a react-native bridge for a payment lib and I have no idea what this syntax mean. Is it calling some function? Ohhh is it calling some function setCallBack... which is a property defined inside the object checkout of MercadoPagoCheckout? And this property accepts a another function as argument and ^{ } is some sort of anonymous function block?

I guess I just found the answer. Nevermind haha

    //Set up Cancellation Callback
    [checkout setCallbackCancelWithCallback:^{
        [uiNavigationController setNavigationBarHidden:TRUE];
        [uiNavigationController popToRootViewControllerAnimated:NO];

        reject(@"PAYMENT_CANCELLED", @"Payment was cancelled by the user.", nil);
    }];

Here is the full code with screenshot just for fun.

enter image description here

RCT_EXPORT_METHOD(startCheckoutForPayment: (NSString *) publicKey: (NSString *) preferenceId: (NSString *) color: (BOOL) enableDarkFont: (RCTPromiseResolveBlock) resolve: (RCTPromiseRejectBlock) reject) {

  UINavigationController *uiNavigationController = (UINavigationController *) [UIApplication sharedApplication].delegate.window.rootViewController;

  MercadoPagoCheckoutBuilder *builder = [[MercadoPagoCheckoutBuilder alloc] initWithPublicKey:publicKey preferenceId:preferenceId];
  MercadoPagoCheckout *checkout = [[MercadoPagoCheckout alloc] initWithBuilder:builder];

  //Set up Cancellation Callback
  [checkout setCallbackCancelWithCallback:^{
      [uiNavigationController setNavigationBarHidden:TRUE];
      [uiNavigationController popToRootViewControllerAnimated:NO];

        reject(@"PAYMENT_CANCELLED", @"Payment was cancelled by the user.", nil);
  }];

...

Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>