If you love reading and sharing books with your friends, but struggle to keep track of which friend has which exact book, then SWAG4PI is the perfect solution for you! Not only can you easily add new books to your collection, but you can also update the book's details to include which friend "checked out" the book and on what date. If you decide to give the book away, you can delete the book from your collection. Sharing books with your friends is fun and easy, and with SWAG4PI keeping track of those books is now fun and easy too!
SWAG4PI's architectural pattern is MVC. BooksTableViewController manages NoDataView, BookTableViewCell and ClearBooksView. DetailViewController manages DetailView and ShareDropDownView. AddBookViewController manages AddBookView. All three controllers interact with the Book model.
I opted to use a singleton creational pattern to handle the data from the server in order to organize the app’s data in one place (BookDataStore). I marked the class as final to ensure that BookDataStore would not be changed or subclassed. I also set sharedInstance as static in order to prevent its methods from being overridden. Finally, the singleton's initializer is marked as private to prevent other objects from creating their own instances of the BookDataStore class.
I chose to make the Book model a class instead of a struct because any changes made to an instance of Book I wanted to be reflected throughout the app; therefore, I determined that a reference type, rather than a value type, was better suited. BookAPICalls, by contrast, I made a struct because its primary purpose is to encapsulate the functions interacting with the server; therefore, there was no need for reference semantics. Marking the functions in BookAPICalls as static allowed me to call these functions without creating an instance of BookAPICalls.