Last active
August 29, 2015 14:18
-
-
Save rjsamson/067382da204418267712 to your computer and use it in GitHub Desktop.
Extension for RLMResults to provide take(limit: Int) and toArray()
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
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