magicalpanda / MagicalRecord

Super Awesome Easy Fetching for Core Data!
Other
10.8k stars 1.79k forks source link

Issues on intial load #1309

Closed multinerd closed 7 years ago

multinerd commented 7 years ago

Maybe someone here can help me?

https://stackoverflow.com/questions/44461402/using-magicalrecord-how-do-i-load-the-data-properly-the-first-time

I am using magical MagicalRecord to save the results my barcode scanner app so that users can later review them (think scan history).

My issue is that i see (null) (see image below) and the only way to get it loaded properly (discovered purely by dumb luck) is to swipe delete any single record. This only happens when the app is launched and if i don't delete a record, it would remain null throughout the life of the app. Once i delete a record, it works fine for the life of the app. My users shouldn't have to remove a record to have it loaded properly. What a i missing?

My setup is the following.

My model class

@interface BSCoreData : NSManagedObject
@property (nonatomic, strong) NSString *itemName, *itemUPC, *scanStore;
@property (nonatomic, strong) NSDate *scanTime;
@property (nonatomic, strong) NSData *itemImage;
@end

UITableViewController

- (void)viewDidLoad {
    ...
     listOfScans = [BSCoreData MR_findAllSortedBy:@"scanTime" ascending:NO]; // listOfScans = NSArray
    [self.tableView reloadData];
    ...
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ...
    BSCoreData *data = [listOfScans objectAtIndex:indexPath.row];
    ...
    // This is how im deleting a record using `MGSwipeTableCell`
    cell.rightButtons = @[[MGSwipeButton buttonWithTitle:@""
                                                    icon:[[UIImage imageNamed:@"UI-Delete"] rt_tintedImageWithColor:[UIColor appTint]]
                                         backgroundColor:[UIColor deleteColor]
                                                callback:^BOOL(MGSwipeTableCell *sender) {
                                                    [data MR_deleteEntity];
                                                    listOfScans = [BSCoreData MR_findAllSortedBy:@"scanTime" ascending:NO]; // listOfScans = NSArray
                                                    [weakself.tableView reloadData];
                                                    return YES;
                                                }]];
    ...
}

My Null Image

multinerd commented 7 years ago

This seems to have fixed itself after i added a new bool property to my model.