0

これは、Swift 3 で UserDefaults を使用して tableView に辞書の配列を保存する正しい方法ですか? var arrNotes = [文字列:文字列]

func saveNotesArray () {
    UserDefaults.standard.set(arrNotes, forKey: "notes")
    UserDefaults.standard.synchronize()
}
4

4 に答える 4

0

your should do it like This For Saving

let placesData = NSKeyedArchiver.archivedData(withRootObject: placesArray)
UserDefaults.standard.set(arrNotes, forKey: "notes")

To Retrieved array from NSUserDefault.

let placesData = UserDefaults.standard.object(forKey: "notes") as? NSData

if let placesData = placesData {
    let arrNotes = NSKeyedUnarchiver.unarchiveObject(with: placesData as Data) as? NSMutableArray
    print(arrNotes)

}

于 2017-01-04T11:00:37.117 に答える