Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Test-Driven iOS Development with Swift 4 - Third Edition

You're reading from  Test-Driven iOS Development with Swift 4 - Third Edition

Product type Book
Published in Oct 2017
Publisher Packt
ISBN-13 9781788475709
Pages 222 pages
Edition 3rd Edition
Languages
Author (1):
Dr. Dominik Hauser Dr. Dominik Hauser
Author Profile Icon Dr. Dominik Hauser
Dr. Dominik Hauser
Toc

Serialization and deserialization

You may notice that the to-do item you put in is gone when you restart the app. Such an app is useless for the user. The app needs to store the to-do items somehow and reload them when it is opened the next time. There are different possibilities to implement this. We could use Core Data, serialize the data using NSCoding, or use a third-party framework. In this book, we will write the date into a property list (plist). A plist has the advantage that it can be opened and altered with Xcode or any other editor.

The data model we implemented uses structs. Unfortunately, structs cannot be written to a plist. We have to convert the data into Any arrays and String:Any dictionaries. Add the following code to ToDoItemTests:

func test_HasPlistDictionaryProperty() { 
  let item = ToDoItem(title: "First") 
  let dictionary = item.plistDict 
}...
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 €18.99/month. Cancel anytime