I should convert this array String "eventi" to data to pass it to a empty property list.
Is there any way?
Here my code...
In the function I am using FileManager create file at Path but in the content section if I insert the Event Array as Data it gives me a crash
var documentsDirectoryURL : URL {
return try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
}
let fileURL = documentsDirectoryURL.appendingPathComponent(String(format: "\(settings.stringa_valore_Giorno) \(settings.nome_Mese) \(settings.nome_Anno) Lista_Eventi.plist"))
self.incrementa_App += 1
self.eventi2.updateValue(String(format: "\(self.incrementa_App)°"), forKey: titolo)
for (key, value) in eventi2 {
eventi.append("\(key), \(value)")
}
if let _ = try? fileURL.checkResourceIsReachable() {
do {
let data = try PropertyListSerialization.data(fromPropertyList: eventi.unique(), format: .binary, options: 0)
// print(eventi.unique())
try? data.write(to: fileURL)
print(fileURL.path)
} catch {
print(error)
}
print("file exists ")
}else {
FileManager.default.createFile(atPath: fileURL.path, contents: eventi as! Data?, attributes: nil)
print(fileURL.path)
print("file not exists")
}
}