All Projects → futurice → mvvm-example-objc

futurice / mvvm-example-objc

Licence: BSD-3-Clause license
Example MVVM structure for iOS apps, written in Objective-C

Programming Languages

objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

Instructions

  • Make the failing test pass
  • Add another view (PersonViewController) with its own view model that's initialized with a person
  • Test that the PersonListViewModel creates the correct PersonViewModel
  • Try fetching data from the internet instead (e.g. https://api.myjson.com/bins/nghk, or create your own JSON there)
  • Add some fields to the model, e.g. an NSDate birthdate that must be formatted

Takeaway points

  • Better separation between UI and state of the app
  • Testing is easier due to cleaner interfaces and dependency injection

Additional material

To fetch data from a JSON backend, you can do something like this in the store:

NSURL *url = [NSURL URLWithString:@"https://api.myjson.com/bins/nghk"];

return [[[NSURLSession sharedSession] rac_GET:url]
    map:^(RACTuple *result) {
        NSData *data = result.first;
        NSArray *peopleArray = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];

        NSMutableArray *people = [NSMutableArray array];
        for (NSDictionary *personDict in peopleArray) {
            Person *person = [[Person alloc] initWithFirstName:personDict[@"firstName"] lastName:personDict[@"lastName"]];
            [people addObject:person];
        }

        return [people copy];
    }];
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].