Search code examples
swiftgenericskey-value-observing

Swift generic Array KVO


I have a generic array

dynamic var tasks : Array<Task> = []

I want it to be generic and dynamic so I can key value observe it. The following error shows up

Property cannot be marked dynamic because its type cannot be represented in Objective-C

I've tried adding @objc to the class that holds tasks and it inherits from NSObject but the error message does not go away.


Solution

  • The problem was that my class Task was not a subclass of NSObject. Adding this removed the error.