Writing Basic Models
Unlike controllers and views, there’s no default superclass that models inherit from; they’re just plain-old Ruby objects. We can use the standard attr_accessor, reader, and writer functions to declare getter and setter methods, which sometimes are all you need.
Many apps have users and profiles, so let’s work through a portion of that sort of app and use some nice models. Let’s create a new project (such as motion create UserProfile) and two subdirectories within ./app: models and controllers. We’re not only going to cover models; we’re going to keep building on what we already know.
Our app will let us create, view, and edit users. Since we’re doing an awful lot of work with users, this sounds like a good place to ...
Get RubyMotion now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.