Created
June 30, 2016 04:14
-
-
Save cbess/c21d08c3a47a97cd1c14d2a10e8cb6d8 to your computer and use it in GitHub Desktop.
Helpul Realm extensions
This file contains hidden or 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
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