-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Realm.isEmpty property #2501
Comments
isEmpty() has a default implementation that just checks the count |
That's right. If the Swift standard library has a function that works with Realm types and reimplementing it ourselves wouldn't offer any performance improvements, we don't reimplement it. Free function in Swift 1.2: http://swiftdoc.org/func/isEmpty/ CollectionType extension in Swift 2.0: http://swiftdoc.org/swift-2/protocol/CollectionType/#prop-isEmpty |
isEmpty() has a default implementation that just checks the count
Cool. We should make sure that is reflected in the API docs as well.
Does this also extend to the Realm?
|
realm/jazzy#8 (and realm/jazzy#190, kind of) would be the appropriate way to solve this I think.
No, since |
> can you think of practical cases in which that would be preferable to
checking if the file exists, or if the count of a particular model class is
empty?
Yes, I have often had need of initializing the data model with some data
form the initial empty state, and while you could select a specific class
to check on, it doesn't really capture the intention.
|
Checking if it was empty also wouldn't capture the intention of having initial data (not just seeding data whenever the Realm is empty, even on subsequent runs). For that, I'd recommend comparing the schema version with |
I guess there are two separate issues: One is to be able to detect if the Realm has just been created so that you can do any initial initialization you would want to do. The other is to detect if the Realm is empty (contains no objects). There are use cases where this would be useful, like if you have lot of Realms and want to delete all the empty ones. This is currently pretty difficult to do manually as you have to find out how to iterate over all the classes in the Realm. I think that both aught to be supported in a way that is easy for users to discover. |
List
andResults
are missing theisEmpty()
method as defined on the CollectionType Protocol.It would also be really useful with an
isEmpty()
method on the Realm object, to show if it contains any objects at all.The text was updated successfully, but these errors were encountered: