Code Monkey home page Code Monkey logo

Comments (5)

sync-by-unito avatar sync-by-unito commented on July 19, 2024

➤ PM Bot commented:

Jira ticket: RCOCOA-2295

from realm-swift.

Jaycyn avatar Jaycyn commented on July 19, 2024

Question: To me, an empty section would just be a section header with no rows following. Is that the case here?

It would be helpful to see a minimal example of the issue so we can see how the sections are being defined and what an 'empty' section would look like.

from realm-swift.

jadar avatar jadar commented on July 19, 2024

Question: To me, an empty section would just be a section header with no rows following. Is that the case here?

It would be helpful to see a minimal example of the issue so we can see how the sections are being defined and what an 'empty' section would look like.

It could be. For example, if you had a hierarchy of data (like a file system) and had a directory without childrens, then you would have an empty section.

The case in our app is that we want to have sections based on that "status" of an object: "Paused" and "Finished". Here are screenshots that depict it.

Simulator Screenshot - iPhone 15 Pro - 2024-02-22 at 14 42 37 MediumSimulator Screenshot - iPhone 15 Pro - 2024-02-22 at 14 42 40 Medium

from realm-swift.

Jaycyn avatar Jaycyn commented on July 19, 2024

Allow me to think through this at kind of a high level here.

It's up to you, the developer to determine how 'sections' are derived. For example, if you have a contact list and want sections by the first letter representing each contact it would be something like this in Swift

@ObservedSectionedResults(Contact.self, sectionKeyPath: \.firstLetter)

or suppose you want to have sections representing States in the US that are stored in your database.

@ObservedSectionedResults(USState.self, sectionKeyPath: \.stateName)

In other words, the section headers are derived from the data itself. If there is no contact starting with "Z" then there's no "Z" section. If there's no state "Florida", there would be no section "Florida".

I would think the simple solution is to pre-populate your database with objects that you know will represent the headers, but with nil or empty properties and a property to indicate if it's a section header or not.

class Contact: Object {
   @Persisted var firstLetter = ""
   @Persisted var contactName = ""
   @Persisted var isHeader = false
}

let contactA = Contact()
contactA.firstLetter = "A"
contactA.isHeader = true

let contactB = Contact()
contatB.firstLetter = "B"
contactB.isHeader = true

then when the app starts, ensure all contacts that are headers are written which forces every section to have a header whether or not there's any actual rows within that header.

From there - just ensure queries exclude headers from their results.

Just a thought!

from realm-swift.

jadar avatar jadar commented on July 19, 2024

That might work. It feels forced but might be a viable workaround. I'll play with it and see how it works.

from realm-swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.