I get mp3 files from Document Directory, I wrote that pathExtension equals "mp3", in the Swift 1.2 it is working, but in the Swift 2.0 I get the error " 'pathExtension' is unavailable: Use pathExtension on NSURL instead."
func fetchFilesFromFolder() {
let fileManager = NSFileManager.defaultManager()
let folderPathURL = fileManager.URLsForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask)[0]
if let directoryURLs = try? fileManager.contentsOfDirectoryAtURL(folderPathURL, includingPropertiesForKeys: nil, options: NSDirectoryEnumerationOptions.SkipsHiddenFiles) {
listOfMP3Files = directoryURLs.map(){ $0.lastPathComponent! }.filter(){ $0.pathExtension == "mp3" } // error is here
}
}
Or you can use this extension:
extension String {
var ns: NSString {
return self as NSString
}
var pathExtension: String {
return ns.pathExtension
}
var lastPathComponent: String {
return ns.lastPathComponent
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With