Repository: realm/realm-swift
File: examples/RealmTableViewExample/RealmTableViewExample/TableViewController.m (Objective-C)

Code before:
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [self.realm beginWriteTransaction];
        [self.table removeRowAtIndex:indexPath.row];
        [self.realm commitWriteTransaction];
    }
}

#pragma mark - Actions

- (void)add {
    [self.realm beginWriteTransaction];
    [self.table addRow:@[[self randomString], [self randomDate]]];
    [self.realm commitWriteTransaction];
}

- (void)deleteAll {
    [self.realm beginWriteTransaction];
    [self.table removeAllRows];
    [self.realm commitWriteTransaction];
}

#pragma - Helpers

- (NSString *)randomString {
    return [NSString stringWithFormat:@"Title %d", arc4random()];
}

- (NSDate *)randomDate {
    return [NSDate dateWithTimeIntervalSince1970:arc4random()];
}

@end


Review comment (suggestion):
I think bgadd is extremely common and should be in there. I think the
current name “RealmTableViewExample” is more descriptive than Basic. It’s
what most people want to build as their first app anyway.

On Wed, May 7, 2014 at 12:12 AM, Kenneth Geisshirt <notifications@github.com

> wrote:
> 
> In
> examples/RealmTableViewExample/RealmTableViewExample/TableViewController.m:
> 
> > @@ -132,25 +119,6 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
> > 
> >  #pragma mark - Actions
> > 
> > -- (void)bgAdd {
> 
> Answer to the poll: definitely maybe.
> 
> My question is: how common is background updating in apps? If common, then
> our example should use it. Otherwise, don't complicate the source code.
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/Tightdb/tightdb_objc/pull/249/files#r12363571
> .


Code after:
    
    return cell;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [self.realm beginWriteTransaction];
        [self.table removeRowAtIndex:indexPath.row];
        [self.realm commitWriteTransaction];
    }
}

#pragma mark - Actions

- (void)backgroundAdd {
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    // Import many items in a background thread
    dispatch_async(queue, ^{
        // Get new realm and table since we are in a new thread
        RLMRealm *realm = [RLMRealm defaultRealm];
        RLMTable *table = [realm tableWithName:kTableName objectClass:[DemoObject class]];
        [realm beginWriteTransaction];
        for (NSInteger index = 0; index < 5; index++) {
            // Add row via dictionary. Order is ignored.
            [table addRow:@{@"title": [self randomString], @"date": [self randomDate]}];
        }
        [realm commitWriteTransaction];
    });
}

- (void)add {
    [self.realm beginWriteTransaction];
    [self.table addRow:@[[self randomString], [self randomDate]]];
    [self.realm commitWriteTransaction];
}

- (void)deleteAll {
    [self.realm beginWriteTransaction];
    [self.table removeAllRows];
    [self.realm commitWriteTransaction];
}

#pragma - Helpers

- (NSString *)randomString {
    return [NSString stringWithFormat:@"Title %d", arc4random()];
}

- (NSDate *)randomDate {
    return [NSDate dateWithTimeIntervalSince1970:arc4random()];
}