Swift 3 for Absolute Beginners by Gary Bennett & Brad Lees

Swift 3 for Absolute Beginners by Gary Bennett & Brad Lees

Author:Gary Bennett & Brad Lees
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA


In Listing 8-12, lines 14 to 27 define the init method of the object, which is called whenever the object is first initialized. In this method, you initialize the two books you plan to add to your bookstore. Line 15 is where the first Book object is allocated and initialized. Lines 16 to 18 add a title, author, and description to your first book. Finally, line 19 adds the new Book object to the theBookStore array. The important thing to note here is that once the object is added to the array, the code can forget about it; the array now owns that object. Because of this, line 21 is not a problem.

Line 21 allocates a new Book object overwriting the old value. This tells the compiler that you’re no longer interested in using the old value.

Lines 22 to 26 simply initialize and add the second book to the array.

That’s it! That’s all you need to define a simple data model class. Next, you need to modify MasterViewController to access this class so that it can start displaying some data.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.