Post

Replies

Boosts

Views

Activity

UserDefaults with Struct - TableView not displaying data from saved from UserDefaults?
I am having problem displaying data on the table view cell These are my code: struct Person: Codable { var firstName: String var lastName: String } class viewController: UIViewController { var newPerson = [Person]() override func viewDidLoad() { let person = [Person(firstName: "Peterson", lastName: "Jota") , Person(firstName: "John", lastName: "Paul")]     let encoder = JSONEncoder()  if let encoded = try? encoder.encode(person) {       UserDefaults.standard.set(encoded, forKey: "savedPerson")     } } } var person = [Person]() func tableView( tableView: UITableView, numberOfRowsInSection section: Int) - Int {     return person.count   } func tableView( tableView: UITableView, cellForRowAt indexPath: IndexPath) - UITableViewCell {     let cell = tableView.dequeueReusableCell(withIdentifier: "cellID", for: indexPath) as! UITableViewCell   cell.textLabel?.text = person[indexPath.row]   return cell }
3
0
1.1k
Apr ’21