dimanche 12 février 2017

IOS/Objective-C: can't save CoreData values into NSArray

Vote count: 0

I'm trying to save CoreData values into an array for later display it in a table view. But so far, the logs show me that the array is empty (null) though there is data in the application. I don't understand why this happens. Can somebody give me a help? Here's the code:

@interface TableViewController ()

@property (strong) NSArray *locations;

@end

@implementation TableViewController

- (NSManagedObjectContext *)managedObjectContext
{
    NSManagedObjectContext *context = nil;
    id delegate = [[UIApplication sharedApplication] delegate];
    if ([delegate respondsToSelector:@selector(managedObjectContext)]){
        context = [delegate managedObjectContext];
    }
    return context;
}


- (void)viewDidLoad {
    [super viewDidLoad];

    self.tableView.dataSource = self;

    NSManagedObjectContext *managedObjectContext = [self managedObjectContext];

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Spot"];
    self.locations = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];

    [self.tableView reloadData];
     NSLog(@"%@ Places are: ", _locations);

    }

asked 59 secs ago

Let's block ads! (Why?)



IOS/Objective-C: can't save CoreData values into NSArray

Aucun commentaire:

Enregistrer un commentaire