I have an object "School" with a mutable array property "favoritesArray" and an NSString property "name".
I have 2 view controllers "HomeViewController" and "FavoritesTableViewController".
In my HomeViewController when a button is tapped this method is called:
self.school=[[School alloc]init];
[self.school.favoritesArray addObject:self.school.name];
NSData *schoolData=[NSKeyedArchiver archivedDataWithRootObject:self.school];
[[NSUserDefaults standardUserDefaults] setObject:schoolData forKey:@"schoolData"];
Then in my "FavoritesTableViewController" I attempt to unarchive the previously archived "school" object so I can access the "favoritesArray".
when a button is tapped in my "FavoritesTableViewController" this method is called:
NSData *dataRetrieved=[[NSUserDefaults standardUserDefaults] objectForKey:@"schoolData"];
School *schoolTwo=[NSKeyedUnarchiver unarchiveObjectWithData:dataRetrieved];
NSLog(@"%lu", (unsigned long)schoolTwo.favoritesArray.count);
However it logs 0 meaning it didn't unarchive the object that was archived in the "HomeViewController".
How do I unarchive the object that was archived in a separate view controller?