我的應用程序中有一個對象數組。我使用這個數組來顯示UICollectionView中對象的屬性。當我關閉/殺死應用程序這個數組被重置,這是正常的。所以我的問題是如何在應用程序關閉時將數組保存在設備的內存中,並在再次打開應用程序時再次獲取數組 - 謝謝。如何在應用程序被殺時保存陣列
消息對象的數組:
static var MessageArr = Array<Message>()
消息類別
import Foundation
import UIKit
class Message: NSObject {
let name : String
let number : String
let email: String
let localDate: String
let localityPostal: String
let administrativeArea: String
let country: String
let streetName: String
let mapImage: UIImage
init(Name : String, Number : String, Email: String = "Ingen E-mail", LocalDate: String, LocalityPostal: String, AdministrativeArea: String, Country: String, StreetName: String, MapImage: UIImage) {
self.name = Name
self.number = Number
self.email = Email
self.localDate = LocalDate
self.localityPostal = LocalityPostal
self.administrativeArea = AdministrativeArea
self.country = Country
self.streetName = StreetName
self.mapImage = MapImage
}
}
使您的課程符合'NSCoding',然後在'applicationWillResignActive'中,將其存檔到您的本地數據文件夾中。 –
http://stackoverflow.com/a/32420488/2303865 –
的可能的副本只是將其保存到ApplicationSupportDirectory文件夾而不是緩存文件夾 –