Skip to content

Instantly share code, notes, and snippets.

@saoudrizwan
Last active December 24, 2017 23:37
Show Gist options
  • Save saoudrizwan/a8a0ebef82ff22977b22440b42a2f51c to your computer and use it in GitHub Desktop.
Save saoudrizwan/a8a0ebef82ff22977b22440b42a2f51c to your computer and use it in GitHub Desktop.
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