So, I recently studied the Realm database and loaded the data into my own table view, and I tried to use RLMResults as an array to get my data in the database and load the elements stored in my RLMResults into my table view in the usual way, My ViewController .m is as follows:
#import "ViewController.h"
#import "customCell.h"
#import "Person.h"
@interface ViewController ()
@property RLMRealm *realm;
@property RLMResults *person;
@end
@implementation ViewController
@synthesize realm, person;
- (void)viewDidLoad {
[super viewDidLoad];
Person *one = [[Person alloc] init];
one.firstName = @"Allen";
one.lastName = @"X";
realm = [RLMRealm defaultRealm];
[realm beginWriteTransaction];
[realm addObject:one];
[realm commitWriteTransaction];
self.person = [Person allObjects];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [person count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
NSString *cellIdentifier = @"cellIdentifier";
customCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.firstName.text = [self.person[indexPath.row] firstName];
cell.lastName.text = [self.person[indexPath.row] lastName];
return cell;
}
@end
And as soon as I compile and run this, Xcode will say such things:
Topic 1: breakpoint 1.2
Can anybody help me?
source
share