Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

When asking for the RRC sections, getting RealmSections without objects #14

Open
polqf opened this issue Aug 14, 2015 · 6 comments
Open

Comments

@polqf
Copy link
Owner

polqf commented Aug 14, 2015

Now, when asking for the RRC sections we are getting a RealmSection object with just its sectionKeyPath

line 173

    private func realmSectionMapper<S>(section: Section<S>) -> RealmSection<U> {
        return RealmSection<U>(objects: nil, keyPath: section.keyPath)
    }
@polqf
Copy link
Owner Author

polqf commented Sep 3, 2015

Added Warning in 0.0.9

@isaacroldan
Copy link
Contributor

Not sure, we can't make the public var sections return all the mapped objects. It will be necessary to remap everything each time it is called, that could affect the performance of the RRC. I would leave it like this for the moment, the RRC works perfectly without this, will refactor in the future to maybe separate in two functions: one to return section info (keypath, without the objects), another one to return all the objects in a section

@jpaas
Copy link

jpaas commented Dec 30, 2015

This may not be the right place to ask, but it seems related. I need to find the indexPath of an object in my rrc in order to select it. I thought that the objects property of RealmSection might be the way to do it, but ain't no objects. Is there any way of getting all of the objects to enumerate them? Or alternatively a way of finding the indexPath for an object?

@polqf
Copy link
Owner Author

polqf commented Dec 30, 2015

Hi @jpaas ,
At the moment we don't have any method to easily do it.

The only thing that comes to my mind with the current configuration is to do something like this:

        let section = //SECTION YOU ARE INTERESTED IN
        for i in 0..<realmResultsController.numberOfObjectsAt(section) {
            let indexPath = NSIndexPath(forRow: i, inSection: section)
            let object = realmResultsController.objectAt(indexPath)
            if /*Check if is the desired object*/ {
                return object
            }
        }

If you have a better idea, feel free to open a PR 😄

@jpaas
Copy link

jpaas commented Dec 30, 2015

Thanks @poolqf that looks like it will do the trick. And thanks for the quick reply! I may very well open a PR. Perhaps a method that takes some sort of block to match criteria would be nice.

@polqf
Copy link
Owner Author

polqf commented Dec 30, 2015

@jpaas That would be highly appreciated 🤗!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants