How can I use checkBlock in swift?

I try to use the fast SKStoreProductViewController, but I get errors with my syntax, especially with my completion block.

Here is my code:

let storeViewController:SKStoreProductViewController = SKStoreProductViewController();
storeViewController.delegate = self;

var productparameters = [SKStoreProductParameterITunesItemIdentifier:someitunesid];

storeViewController.loadProductWithParameters(productparameters,
    (success: Bool!, error: NSError!) -> Void in
        if success {
    self.presentViewController(storeViewController, animated: true, completion: nil);
        } else {
        NSLog("%@", error)
    }
  )

After starting, I get an error expected "," separatorbetweenerror:NSError!),-> Void

This does not make sense to me, as apple documents require:

func loadProductWithParameters(_ parameters: [NSObject : AnyObject]!,
           completionBlock block: ((Bool, NSError!) -> Void)!)

What am I doing wrong?

+4
source share
1 answer

You are 99%, you need parentheses around your block to have the correct closing syntax:

storeViewController.loadProductWithParameters(productparameters, { (success: Bool!, error: NSError!) -> Void in
    if success {
        self.presentViewController(storeViewController, animated: true, completion: nil);
    } else {
        NSLog("%@", error)
    }
})

You can read more about closing Apple documentation .

+3
source

Source: https://habr.com/ru/post/1547095/


All Articles