Saving App Data in Property List FilesYour app needs to save data. There's too much data to use User Defaults. Using SwiftData or Core Data would be overkill. One solution is to save the data in property list files. This article shows you how to save your app's data in property list files. Use the PropertyListEncoder Class if you canIf the data you want to save conforms to the
The following code encodes an object to an XML property list:
Use the PropertyListDecoder Class to DecodeNormally when your app encodes data, it also needs to decode the data. Use the The following code decodes an object from an XML property list:
Replace Use NSKeyedArchiver if you can't use PropertyListEncoderIf the data you want to save doesn't conform to
Encoding to XMLThe default property list format is binary so using the
The
Use NSKeyedUnarchiver to UnarchiveUse the
If you are unarchiving an XML property list, you must do the following:
The following code unarchives the object that the
Newsletter ArchiveYou can read previous issues of the newsletter using the following button:
|
Subscribe and get exclusive articles on Swift development, a free guide on moving from tutorials to making your first app, notices of sales on books, and anything I decide to add in the future.
If you find your app becomes unresponsive at times, it can be frustrating to find the cause. Instruments includes a Hangs instrument that reports hangs to help you find and fix hangs. This article shows you how to use the Hangs and Time Profiler instruments to find hangs and find the code causing the hangs. Profiling Your App In Xcode press Cmd-I to build and profile your app with Instruments. When Instruments launches, it will ask you to choose a template for profiling. Select the Time...
Working with Lists in Multiplatform SwiftUI Apps One of SwiftUI's best features is you can use it to make apps that run on both iOS and Mac. Almost every SwiftUI article you find online is about iOS development, but most of the material also applies to Mac as well. Lists are one area of SwiftUI where there are large differences between iOS and Mac. If you read an article about lists and try to use the code in a Mac app, you'll run into problems. This article provides guidance on writing list...
Getting Started with Document-based SwiftUI Apps Document-based apps let people create documents they can share with others. Examples of document-based apps are text editors, spreadsheets and video editors. Learn the basics of making document-based SwiftUI apps in this article. Creating a Project in Xcode The iOS, Mac, and Multiplatform project categories have a Document App project template. Select that template and click the Next button to create a document app. Multiplatform document apps...