Post

Replies

Boosts

Views

Activity

Reply to How to pass data through TabBarController?
Sorry, I saw your message just today. Yes, of course, this is the code.     // MARK: - Saving Data to Archive File          // 1. Make a path to save and upload data.     static let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!     static let archiveUrl = documentsDirectory.appendingPathComponent("classes").appendingPathExtension("plist")          // 2. Encoding and saving data.     static func saveToFile(classes: [ClassUnit]) {         let propertyListEncoder = PropertyListEncoder()         let encodeClasses = try? propertyListEncoder.encode(classes)         try? encodeClasses?.write(to: archiveUrl, options: .noFileProtection)              }     // 3. Deconding and load data.     static func loadFromFile() -> [ClassUnit] {         let propertyListDecoder = PropertyListDecoder()         var classes = [ClassUnit]()         if let retrivedClassesData = try? Data(contentsOf: archiveUrl), let decodeClasses = try? propertyListDecoder.decode(Array<ClassUnit>.self, from: retrivedClassesData) {             classes = decodeClasses         }         return classes     } You can see more about this method in Apple's textbook called App Development with Swift. It can be found in iBookStore.
Jul ’20