Encoding and Decoding Objects - Saving Data in iOS - raywenderlich.com

Published: 18 August 2017
on channel: Kodeco
8,979
84

Learn how to save your object graph to disc using the NSCoding protocol.

Updated course: https://videos.raywenderlich.com/cour...

---

About www.raywenderlich.com:

raywenderlich.com is a website focused on developing high quality programming tutorials. Our goal is to take the coolest and most challenging topics and make them easy for everyone to learn – so we can all make amazing apps.

Update course: https://videos.raywenderlich.com/cour...

We are also focused on developing a strong community. Our goal is to help each other reach our dreams through friendship and cooperation. As you can see below, a bunch of us have joined forces to make this happen: authors, editors, subject matter experts, app reviewers, and most importantly our amazing readers!

---

In this course, you’ll take a tour of the many different ways to save data in iOS, such as User Defaults, Property Lists, NSCoding, and more.

A protocol that enables an object to be encoded and decoded for archiving and distribution.

The NSCoding protocol declares the two methods that a class must implement so that instances of that class can be encoded and decoded. This capability provides the basis for archiving (where objects and other structures are stored on disk) and distribution (where objects are copied to different address spaces).
In keeping with object-oriented design principles, an object being encoded or decoded is responsible for encoding and decoding its instance variables. A coder instructs the object to do so by invoking
encode(with:) or init(coder:).

encode(with:) instructs the object to encode its instance variables to the coder provided; an object can receive this method any number of times. init(coder:) instructs the object to initialize itself from data in the coder provided; as such, it replaces any other initialization method and is sent only once per object. Any object class that should be codeable must adopt the NSCoding protocol and implement its methods.

It is important to consider the possible types of archiving that a coder supports. In macOS 10.2 and later, keyed archiving is preferred. You may, however, need to support classic archiving. For details, see Archives and Serializations Programming Guide.


Watch video Encoding and Decoding Objects - Saving Data in iOS - raywenderlich.com online, duration hours minute second in high quality that is uploaded to the channel Kodeco 18 August 2017. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 8,979 times and liked it 84 visitors.