2017-08-30 74 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

你不明白的兄弟? –

相关问题