Skip to content

Correct way to update MutableObservableArray2D from signals #692

Open
@yhdzhang

Description

@yhdzhang

Hi all,

I have declared a MutableObservableArray2D as a property in my class which is used as a CollectionView data source. I have multiple signals which generate section data for my CollectionView data source. What is the correct way to update MutableObservableArray2D ?
I have been doing it like below in my project, but i'm starting to have weird timing issues.

let sections = MutableObservableArray2D(Array2D<String, String>(sectionsWithItems: [
    ("foo", []),
    ("bar", []),
]))

func start() {
    SafeSignal<String>(just: "foo").observeNext { string in
        self.sections.replaceItems(ofSectionAt: 0, with: [string], performDiff: false)
    }
    .dispose(in: bag)

    SafeSignal<String>(just: "bar").observeNext { string in
        self.sections.replaceItems(ofSectionAt: 1, with: [string], performDiff: false)
    }
    .dispose(in: bag)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions