如何在MKMapItem
的帮助下保存和检索UserDefaults
的数组?
var recentDestination: [MKMapItem] = []
答案 0 :(得分:1)
由于module Is_lit
open FStar.Tactics
let is_literal (t: term) =
match inspect_ln t with
| Tv_Const (C_String _) -> true
| _ -> false
let check_literal (s: string)
(#[(if (normalize_term (is_literal (quote s)))
then exact (`())
else fail "not a litteral")
] witness: unit)
: unit =
()
// success
let _ = check_literal "hey"
// failure
[@expect_failure]
let _ = let s = "hey" in check_literal s
符合MKMapItem
,因此您可以使用NSCoding
以[MKMapItem]
的形式Data
以UserDefaults
的形式保存{strong} {1}},即
NSKeyedArchiver
Similary,要像这样从let data = NSKeyedArchiver.archivedData(withRootObject: recentDestination)
UserDefaults.standard.set(data, forKey: "recentDestination")
提取保存的数据,请使用UserDefaults
,
NSKeyedUnarchiver
答案 1 :(得分:0)
UserDefaults不应用于存储大于数字/字符串/布尔值的数据。为此,您应该使用NSKeyArchiver