I am trying to save a [MPMediaEntityPersistentID]
using NSUserDefaults.standardUserDefaults();
however, I cannot cast the MPMediaEntityPresitstentID
to a type which can be saved.
Here is the code:
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
}
}
Question:
- Can anyone offer me a solution as to how I can save songID into NSUserDefaults?