How to observe an array of NSObjects in swift?
The error is because marketIndexList
is defined as Array<MarketIndex>
but you assigned Observable
instance. Perhaps you wanted to do something like this:
var observableList: Observable = Observable([])var marketIndexList: Array<MarketIndex> = [MarketIndex(), MarketIndex()]observableList.value = marketIndexList // Or maybeobservableList = Observable(marketIndexList)
By the way, you can also use Objective-C KVO from Swift. Just mark the property as dynamic
and make sure the class inherits NSObject to make the property observable. For example:
class ObservableClass: NSObject { dynamic var value = [Int]()}
This post is good to read for KVO in Swift in addition to what you referred to.https://medium.com/proto-venture-technology/the-state-of-kvo-in-swift-aa5cb1e05cba