How to save a swift struct to file
问题 I want to use structs for the (very simple) model of my app. However NSKeyedArchiver only accepts objects (extending NSObjects ). Is there any good way to save a struct to a file? 回答1: A very simple approach I used sometimes. The quantity of code you need to write is no more then in the class/NSCoding scenario. First of all import the great SwiftyJSON lib. Let's start with a simple struct struct Starship { let name: String let warpSpeed: Bool let captain: String? init(name: String, warpSpeed: