ObservableArray-RxSwift icon indicating copy to clipboard operation
ObservableArray-RxSwift copied to clipboard

ObservableArray as Swift Array replacement

Open darrarski opened this issue 8 years ago • 0 comments

I am not sure if it's possible, but it would be nice to be able to use ObservableArray as a replacement for Swift Array type, without publicly exposing the ObservableArray type. This example should explain what I mean:

var items: [String] = ObservableArray<String>()

or

public class SomeClass {
    public var items: [String] { return itemsObservableArray }
    private var itemsObservableArray = ObservableArray<String>()
}

A workaround that does not require massive changes in the source code would be to make elements property publicly readonly. This way we could do that:

public class SomeClass {
    public var items: [String] { return itemsObservableArray.elements }
    private var itemsObservableArray = ObservableArray<String>()
}

But this is not exactly how I would like to use it. I don't want to get copy of contained array, but rather use the array itself like it would be standard Swift Array.

Do you think it's possible to implement such behavior for ObservableArray? I am open for discussion.

darrarski avatar Dec 04 '16 22:12 darrarski