Reputation: 916
How can i transfer array to table in Today Extansion (Swift)
I'm new to this and nothing happens
In main app i have a table with data
In Today Extansion i have a table (in which the data should be displayed)
its work with TEXT but not work with ARRAY
var myData: [String] = []
MainVC.swift
if let userDefaults = UserDefaults(suiteName: "group.Name1") {
userDefaults.set("Test12345" as AnyObject, forKey: "key3")
userDefaults.synchronize()
}
TodayExtVC.swift
In ViewDidLoad:
if let userDefaults = UserDefaults(suiteName: "group.Name1") {
let value2 = userDefaults.string(forKey: "key3")
print("\(value2)")
}
Upvotes: 1
Views: 123
Reputation: 100523
Set in MainVC.swift
let array = ["horse", "cow", "camel", "sheep", "goat"]
userDefaults.set(array, forKey: "key3")
get in TodayExtVC.swift
let myarray = userDefaults.stringArray(forKey: "key3") ?? [String]()
Upvotes: 2