swift 2 等同于 swift 3 "string contains" 函数是什么?通过 npn.dev

What is the swift 2 equivalent to the swift 3 "string contains" function? by npn.dev

您好, 我想知道什么是 Swift 3

mySong.contains

for Swift 2 on Xcode 7(因为我想为 iPhone 4 创建一个应用程序)。请原谅我的英语,因为我是法国人... google 翻译帮助我

我的代码:

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

我在 swift 2 和 Xcode 7.3.1

中使用 range string 方法
let string = "This is only a test"

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

希望对您有所帮助。