Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static func saveAlbums() {
- let encodedAlbums = objects.map { (album) -> Data in
- return NSKeyedArchiver.archivedData(withRootObject: album)
- }
- UserDefaults.standard.set(encodedAlbums, forKey: "albums")
- }
- override func viewDidAppear(_ animated: Bool) {
- if (MasterViewController.objects.count > 0) {
- return
- }
- if let albums = UserDefaults.standard.object(forKey: "albums") as? [Data]{
- print("there is albums")
- let decoded = albums.map({ (data) -> Album in
- return (NSKeyedUnarchiver.unarchiveObject(with: data) as? Album)!
- })
- MasterViewController.objects = decoded;
- DispatchQueue.main.async {
- self.tableView.reloadData()
- }
- } else {
- loadAlbums()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement