我正在尝试使用[MPMediaEntityPersistentID]
保存NSUserDefaults.standardUserDefaults();
但是,我无法将MPMediaEntityPresitstentID
转换为可以保存的类型。
以下是代码:
import Foundation
import AVFoundation
import MediaPlayer
class SaveFileArray
{
var songFileArray = [MPMediaEntityPersistentID]()
init() {
songFileArray = []
}
func saveFile(id: MPMediaEntityPersistentID) {
let songID = id as NSString
songFileArray.append(id)
//Instead of printing lets save the MPMediaEntityPersistentID
print(songFileArray[0])
NSUserDefaults.standardUserDefaults().setObject(songFileArray, forKey: "time")
NSUserDefaults.standardUserDefaults().synchronize()
}
func countSavedFiles() -> Int {
return songFileArray.count
}
}
问题: