Skip to content

Instantly share code, notes, and snippets.

@cbess
Created June 30, 2016 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbess/c21d08c3a47a97cd1c14d2a10e8cb6d8 to your computer and use it in GitHub Desktop.
Save cbess/c21d08c3a47a97cd1c14d2a10e8cb6d8 to your computer and use it in GitHub Desktop.
Helpul Realm extensions
extension List {
/// Return a new array from the List elements
func newArray() -> [T] {
var items = [T]()
for item in self {
items.append(item)
}
return items
}
/// Appends the specified element only once
/// - Returns: true if appended, otherwise false
func appendOnce(element: T) -> Bool {
if !contains(element) {
append(element)
return true
}
return false
}
/// Deletes the contents of the List from it's Realm
func deleteContents() {
for item in self {
realm?.delete(item)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment