Repository: realm/realm-swift
File: examples/iOSTutorial/AppDelegate.m (Objective-C)

Code before:
    NSUInteger cnt2 = [people rowCount];                      // cnt = 5
    // @@EndExample@@

    // @@Example: iteration @@
    for (NSUInteger i = 0; i < people.rowCount; ++i) {
        PeopleTable_Cursor *row = people[i];
        NSLog(@"%@ is %lld years old", row.Name, row.Age);
    }
    // @@EndExample@@

    // @@Example: simple_seach @@
    NSUInteger row_id;
    row_id = [people.Name find:@"Philip"];                 // (NSUInteger)-1: Not found
    row_id = [people.Name find:@"Mary"];                   // row = 1
    // @@EndExample@@

    // @@Example: advanced_search @@
    // Create query (current employees between 20 and 30 years old)
    PeopleTable_Query *q = [[[people where].Hired columnIsEqualTo:YES]
                                           .Age   columnIsBetween:20 and_:30];

    // Get number of matching entries
    NSUInteger cnt3 = [q countRows];                            // =&gt; 2

    // Get the average age (currently only a low-level interface)
    double avg = [q.Age avg];

    // Execute the query and return a table (view)
    PeopleTable_View *res = [q findAll];
    for (NSUInteger i = 0; i < res.rowCount; ++i) {
        NSLog(@"%zu: %@ is %lld years old", i, people[i].Name, people[i].Age);
    }

    // Alternatively with fast emunaration
    for (PeopleTable_Cursor *c in res)
        NSLog(@"%@ is %lld years old", c.Name, c.Age);

    // @@EndExample@@

}

void sharedGroupFunc() {

    // @@Example: transaction @@
    TDBSharedGroup *sharedGroup = [TDBSharedGroup sharedGroupWithFile:@"people.tightdb"
                                                            withError:nil];

    // Start a write transaction
    [sharedGroup writeWithBlock:^(TDBGroup *group) {
        // Get a specific table from the group
        PeopleTable *table = [group getOrCreateTableWithName:@"employees"

Review comment (suggestion):
Query accessors should also return objective-c types. In this case it should probably just be NSNumber.


Code after:
    NSUInteger cnt2 = people.rowCount;                  // cnt = 5
    // @@EndExample@@

    // @@Example: iteration @@
    for (NSUInteger i = 0; i < people.rowCount; ++i) {
        PeopleTable_Cursor *row = people[i];
        NSLog(@"%@ is %lld years old", row.Name, row.Age);
    }
    // @@EndExample@@

    // @@Example: simple_seach @@
    NSUInteger row_id;
    row_id = [people.Name find:@"Philip"];              // (NSUInteger)-1: Not found
    row_id = [people.Name find:@"Mary"];                // row = 1
    // @@EndExample@@

    // @@Example: advanced_search @@
    // Create query (current employees between 20 and 30 years old)
    PeopleTable_Query *q = [[[people where].Hired columnIsEqualTo:YES]
                                           .Age   columnIsBetween:20 and_:30];

    // Get number of matching entries
    NSUInteger cnt3 = [q countRows];                     // =&gt; 2

    // Get the average age (currently only a low-level interface)
    double avg = [q.Age avg];

    // Execute the query and return a table (view)
    PeopleTable_View *res = [q findAll];

    // fast emunaration on view
    for (PeopleTable_Cursor *c in res)
        NSLog(@"%@ is %lld years old", c.Name, c.Age);

    // @@EndExample@@

}

void sharedGroupFunc() {
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    [fileManager removeItemAtPath:@"people.tightdb" error:&error];

    // @@Example: transaction @@
    TDBSharedGroup *sharedGroup = [TDBSharedGroup sharedGroupWithFile:@"people.tightdb"
                                                            withError:nil];

    // Start a write transaction
    [sharedGroup writeWithBlock:^(TDBGroup *group) {
        // Get a specific table from the group