swift2 swift 2中什么是swift 3的“字符串包含”函数的等价函数npn.dev

sf6xfgos  于 2022-11-06  发布在  Swift
关注(0)|答案(1)|浏览(208)
  • 你好,我想知道什么是Swift 3*

mySong.contains

  • Xcode 7上的Swift 2(因为我想为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
50few1ms

50few1ms1#

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

let string = "This is only a test"

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

希望能对你有所帮助。

相关问题