2017-08-30 3 views
1

, Ich möchte wissen, was ist das Äquivalent von Swift 3Was ist die swift 2 entspricht der schnellen 3 "String enthält" -Funktion? Hallo von npn.dev

mySong.contains

für Swift 2 auf Xcode 7 (weil ich es will Erstellen Sie eine Anwendung für iPhone 4). Entschuldigen Sie mich für mein Englisch, weil ich bin französisch ... und Google Übersetzung helfen mir

Mein Code:

func gettingSongName(){ 

    let folderURL = NSURL(fileURLWithPath: NSBundle.mainBundle().resourcePath!) 

    do{ 

     let songPath = try NSFileManager.defaultManager().contentsOfDirectoryAtURL(folderURL, includingPropertiesForKeys: nil, options: .SkipsHiddenFiles) 

     for song in songPath{ 

      var mySong = song.absoluteString 

      if mySong.contains(".mp3") { // Value of type 'String' has no member 'contains' 

       let findString = mySong.components(separatedBy: "/") // Value of type 'String' has no member 'components' 
       mySong = findString[findString.count-1] 
       mySong = mySong.replacingOccurrences(of: "%20", with: " ") // Value of type 'String' has no member 'replacingOccurences' 
       mySong = mySong.replacingOccurrences(of: "e%CC%81", with: "é") // Value of type 'String' has no member 'replacingOccurences' 
       mySong = mySong.replacingOccurrences(of: "e%CC%82", with: "ê") // Value of type 'String' has no member 'replacingOccurences' 
       mySong = mySong.replacingOccurrences(of: ".mp3", with: "") // Value of type 'String' has no member 'replacingOccurences' 
       songs.append(mySong) 
       print(mySong) 

      } 

     } 

     myTableView.reloadData() 

    }catch{ 

    } 

} 

danken Ihnen im Voraus, npn.dev

Antwort

2

Ich verwende range string Methode in Swift 2 und Xcode 7.3.1

let string = "This is only a test" 

if string.rangeOfString("only") != nil { 
print("yes") 
} 

Ich hoffe, es wird Ihnen helfen.

+0

danke, ich werde versuchen –

+0

Ich verstehe nicht @Pal Singh Anand –

+0

was Sie nicht verstehen, bro? –

Verwandte Themen