Search code examples
swiftstorelaunch

Launching the App Store from an iOS application in swift


What is wrong with this code?

   @IBAction func Button(sender: AnyObject) {

    NSString *iTunesLink = @"https://itunes.apple.com/us/app/apple-store/id375380948?mt=8";
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
}

I keep getting several errors such as "Expected Declaration", "Expected an attribute name" etc


Solution

  • Seems like you're mixing up Objective-C and Swift.

    If you're using Swift, try:

    var iTunesLink = "https://itunes.apple.com/us/app/apple-store/id375380948?mt=8"
    UIApplication.sharedApplication().openURL(NSURL(string: iTunesLink)!)