Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Full-Stack Development with Swift

You're reading from   Hands-On Full-Stack Development with Swift Develop full-stack web and native mobile applications using Swift and Vapor

Arrow left icon
Product type Paperback
Published in Mar 2018
Publisher Packt
ISBN-13 9781788625241
Length 356 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ankur Patel Ankur Patel
Author Profile Icon Ankur Patel
Ankur Patel
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting Started with Server Swift 2. Creating the Native App FREE CHAPTER 3. Getting Started with Vapor 4. Configuring Providers, Fluent, and Databases 5. Building a REST API using Vapor 6. Consuming API in App 7. Creating Web Views and Middleware 8. Testing and CI 9. Deploying the App 10. Adding Authentication 11. Building a tvOS App 12. Other Books You May Enjoy

Adding a Shopping List Item


If you have successfully implemented the create and delete functionality for an item in the Shopping List, then good job! If not, we will walk through how you can do so. It is very similar to how we implemented it on the Shopping List. To implement the functionality for adding items to a Shopping List, we need to follow these steps:

  1. Open the Item.swift file inside the iOS project and add a new instance variable to store the shoppingListId. This variable will be passed to the API server along with the name and the isChecked state of the item when creating it so that it can associate this item with the shopping list it is being added to:
var shoppingListId: String?
  1. Add the data commuted property, similar to the one we added in the ShoppingList class, which will convert our object into JSON data that will be passed to our API server. In this case, we will use JSONEncoder instead of JSONSerializer. The reason why we did not convert ShoppingList to JSON data using this...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime