2016-04-08 11 views
-5

Ich bin neu zu siwft und habe das folgende Problem, wenn mir jemand helfen kann. danke.Swift - Wie zu verwenden, wenn lassen

func openLink(toUrl: String) { 

    if toUrl == "AppleStoreReview" { 
     let Link: String = "itms-apps://itunes.apple.com/hk/app/my-public-ip/id1093560803" 
    } 
    UIApplication.sharedApplication().openURL(NSURL (string: Link)!) 
} 

enter image description here

Antwort

1

Sie haben den Anruf zu openURL in der if-Anweisung zu bewegen, weil die Link Variable in nur verfügbar:

func openLink(toUrl: String) { 
    if toUrl == "AppleStoreReview" { 
     let Link = "itms-apps://itunes.apple.com/hk/app/my-public-ip/id1093560803" 
     UIApplication.sharedApplication().openURL(NSURL(string: Link)!) 
    } 
} 

ich auch die explizite Typanmerkung entfernt für die Link Konstante, weil es vom Compiler abgeleitet werden kann.

Verwandte Themen