SHARE
TWEET

Untitled

a guest Nov 14th, 2017 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     static func saveAlbums() {
  3.         let encodedAlbums = objects.map { (album) -> Data in
  4.             return NSKeyedArchiver.archivedData(withRootObject: album)
  5.         }
  6.         UserDefaults.standard.set(encodedAlbums, forKey: "albums")
  7.        
  8.     }
  9.  
  10.  
  11. override func viewDidAppear(_ animated: Bool) {
  12.         if (MasterViewController.objects.count > 0) {
  13.             return
  14.         }
  15.        
  16.         if let albums = UserDefaults.standard.object(forKey: "albums") as? [Data]{
  17.             print("there is albums")
  18.             let decoded = albums.map({ (data) -> Album in
  19.                 return (NSKeyedUnarchiver.unarchiveObject(with: data) as? Album)!
  20.             })
  21.            
  22.             MasterViewController.objects = decoded;
  23.             DispatchQueue.main.async {
  24.                 self.tableView.reloadData()
  25.             }
  26.         } else {
  27.             loadAlbums()
  28.         }
  29.     }
RAW Paste Data
Top