如何保存MKMapItem类型的数组

时间:2019-06-05 15:24:47

标签: ios swift mapkit nsuserdefaults

如何在MKMapItem的帮助下保存和检索UserDefaults的数组?

var recentDestination: [MKMapItem] = []

2 个答案:

答案 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]的形式DataUserDefaults的形式保存{strong} {1}},即

NSKeyedArchiver

Similary,要像这样从let data = NSKeyedArchiver.archivedData(withRootObject: recentDestination) UserDefaults.standard.set(data, forKey: "recentDestination") 提取保存的数据,请使用UserDefaults

NSKeyedUnarchiver

答案 1 :(得分:0)

UserDefaults不应用于存储大于数字/字符串/布尔值的数据。为此,您应该使用NSKeyArchiver