Skip to content

Instantly share code, notes, and snippets.

@rjsamson
Last active August 29, 2015 14:18
Show Gist options
  • Save rjsamson/067382da204418267712 to your computer and use it in GitHub Desktop.
Save rjsamson/067382da204418267712 to your computer and use it in GitHub Desktop.
Extension for RLMResults to provide take(limit: Int) and toArray()
import Realm
extension RLMResults {
func take (limit: Int) -> [RLMObject] {
var array = [RLMObject]()
let indices: UInt = limit < Int(self.count) ? UInt(limit) - 1 : self.count - 1
for index in 0...indices {
array.append(self[index] as RLMObject)
}
return array
}
func toArray() -> [RLMObject] {
var array = [RLMObject]()
for result in self {
array.append(result as RLMObject)
}
return array
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment