Last active
December 24, 2017 23:37
-
-
Save saoudrizwan/a8a0ebef82ff22977b22440b42a2f51c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Message { | |
let id: String | |
let body: String | |
} | |
let messages = [Message(id: "1", body: "..."), Message(id: "2", body: "..."), Message(id: "3", body: "...")] | |
// or retrieve your messages from Disk... | |
let messages = try! Disk.retrieve("messages.json", from: .documents, as: [Message].self) | |
var messagesWithoutIdOf2 = [Message]() | |
for message in messages where message.id != 2 { | |
messagesWithoutIdOf2.append(message) | |
} | |
// or if you want to get functional... | |
let messagesWithoutIdOf2 = messages.filter { $0.id != 2 } | |
// now save this updated array to disk... | |
try! Disk.save(messagesWithoutIdOf2, to: .documents, as: "messages.json") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment