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 (performance):
With all the example renaming, I lost track of our examples a bit :-) So
I'm not sure where this fits now.
Is this our "tutorial" example?

I guess we need one very simple "hello world" like app, which shows the
basics: "BasicExample" or "HelloRealm"
Then another which shows most features (showcase the whole API) in one way
or another "FullTutorial". This feature could then be in the "Full". But I
guess we don't have that distinction now.

On Tue, May 6, 2014 at 7:10 PM, JP Simard 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 {
> 
> Can we take a quick poll on this @Tightdb/ioshttps://github.com/orgs/Tightdb/teams/ios?
> Background Add in table view example.
> 
> Yay/Nay?
> 
> Pros: demonstrates a very useful concept that 95% of developers will need
> to do
> Cons: adds complexity to the app (navbar button, longpress gesture to
> delete all, blocks the other add method for short periods)
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/Tightdb/tightdb_objc/pull/249/files#r12335757
> .


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()];
}