Repository: realm/realm-swift
File: doc/ref/examples/ex_objc_table_dynamic_intro.m (Objective-C)

Code before:
/* @@Example: ex_objc_table_dynamic_intro @@ */

#import <tightdb/objc/tightdb.h>



int main()
{
    @autoreleasepool {

        /* Create a new table dynamically. */
        TDBTable *table = [[TDBTable alloc] init];

        NSUInteger const NAME = [table addColumnWithName:@"Name" andType:TDBStringType];
        NSUInteger const AGE = [table addColumnWithName:@"Age" andType:TDBIntType];

        /* Add a row with values. */
        TDBRow *row;
        row = [table addEmptyRow];

        [row setInt:23 inColumnWithIndex:AGE];
        [row setString:@"Joe" inColumnWithIndex:NAME];

        /* And a few more rows - in a simpler manner */
        [table appendRow:@[@32, @"Simon"]];
        [table appendRow:@[@12, @"Steve"]];
        [table appendRow:@[@100, @"Nick"]];

        /* Print using a cursor. */
        for (TDBRow *ite in table)
            NSLog(@"Name: %@ Age: %lld", [ite stringInColumnWithIndex:NAME], [ite intInColumnWithIndex:AGE]);
        
        /* Insert a row and print. */
        row = [table insertEmptyRowAtIndex:2];
        [row setInt:21 inColumnWithIndex:AGE];
        [row setString:@"Hello I'm INSERTED" inColumnWithIndex:NAME];

        NSLog(@"--------");

        for (TDBRow *ite in table)
            NSLog(@"Name: %@ Age: %lld", [ite stringInColumnWithIndex:NAME], [ite intInColumnWithIndex:AGE]);


        /* Update a few rows and print again. */
        table[2][@"Name"] = @"Now I'm UPDATED";

        row = [table lastRow];
        [row setString:@"I'm UPDATED" inColumnWithIndex:NAME];

        NSLog(@"--------");

Review comment (suggestion):
In general we should guide people towards using the dictionary form, rather than the compact representation. Not only may it be more readable (and obj-c like), but it will really help them when they later update the schema.


Code after:
/* @@Example: ex_objc_table_dynamic_intro @@ */

#import <Tightdb/Tightdb.h>

void ex_objc_table_dynamic_intro()
{
    @autoreleasepool {

        /* Create a new table dynamically. */
        TDBTable *table = [[TDBTable alloc] init];

        NSUInteger const NAME = [table addColumnWithName:@"Name" andType:TDBStringType];
        NSUInteger const AGE = [table addColumnWithName:@"Age" andType:TDBIntType];

        /* Add a row with values. */
        TDBRow *row;
        row = [table addEmptyRow];

        [row setInt:23 inColumnWithIndex:AGE];
        [row setString:@"Joe" inColumnWithIndex:NAME];

        /* And a few more rows - in a simpler manner */
        [table appendRow:@[@32, @"Simon"]];
        [table appendRow:@[@12, @"Steve"]];
        [table appendRow:@[@100, @"Nick"]];

        /* Print using a cursor. */
        for (TDBRow *ite in table)
            NSLog(@"Name: %@ Age: %lld", [ite stringInColumnWithIndex:NAME], [ite intInColumnWithIndex:AGE]);
        
        /* Insert a row and print. */
        row = [table insertEmptyRowAtIndex:2];
        [row setInt:21 inColumnWithIndex:AGE];
        [row setString:@"Hello I'm INSERTED" inColumnWithIndex:NAME];

        NSLog(@"--------");

        for (TDBRow *ite in table)
            NSLog(@"Name: %@ Age: %lld", [ite stringInColumnWithIndex:NAME], [ite intInColumnWithIndex:AGE]);


        /* Update a few rows and print again. */
        table[2][@"Name"] = @"Now I'm UPDATED";

        row = [table lastRow];
        [row setString:@"I'm UPDATED" inColumnWithIndex:NAME];

        NSLog(@"--------");

        for (TDBRow *ite in table)