2017-08-30 73 views
1

你好, 我想知道什麼是斯威夫特相當於3什麼是swift 2相當於swift 3「string contains」函數?通過npn.dev

mySong.contains

爲斯威夫特2的Xcode 7(因爲我想爲iPhone 4創建一個應用程序)。對不起,我的英語,因爲我是法國人...和谷歌翻譯幫我

我的代碼:

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{ 

    } 

} 

預先感謝您, npn.dev

回答

2

我使用swift 2中的range string方法和Xcode 7.3.1

let string = "This is only a test" 

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

希望它能幫助你。

+0

謝謝,我會嘗試 –

+0

我不明白@Pal Singh Anand –

+0

你不明白的兄弟? –

相關問題