Makes views use monsters from CoreData instead of hard coded ones.

This commit is contained in:
2020-09-12 01:16:56 -07:00
parent f61fdc0aba
commit 1e79bc5500
3 changed files with 26 additions and 20 deletions

View File

@@ -18,17 +18,18 @@
@end
@implementation SearchViewController
@implementation SearchViewController {
NSManagedObjectContext *_context;
}
- (void)viewDidLoad {
[super viewDidLoad];
AppDelegate *appDelegate = (AppDelegate*)UIApplication.sharedApplication.delegate;
NSManagedObjectContext *context = appDelegate.persistentContainer.viewContext;
Monster *pixie = [[Monster alloc] initWithContext:context];
pixie.name = @"Pixie";
Monster *acolyte = [[Monster alloc] initWithEntity:[NSEntityDescription entityForName:@"Monster" inManagedObjectContext:context] insertIntoManagedObjectContext:nil];
acolyte.name = @"Acolyte";
self.allMonsters = [NSArray arrayWithObjects:acolyte, pixie, nil];
_context = appDelegate.persistentContainer.viewContext;
}
- (void)viewWillAppear:(BOOL)animated {
self.allMonsters = [_context executeFetchRequest:[Monster fetchRequest] error:nil];
self.foundMonsters= self.allMonsters;
}