I have a Swift project that contains two UITableViewControllers
. The second UITableViewController
is linked to a MVC model called Model
. According to the UITableViewCell
I select in the first UITableViewController
, I want to initialize some properties of Model
with Ints
or Strings
. Therefore, I've decided to define those properties with Printable
protocol type. In the same time, I want to perform Key Value Observing on one of these properties.
Right now, Model
looks like this:
class Model: NSObject {
let title: String
let array: [Printable]
dynamic var selectedValue: Printable //error message
init(title: String, array: [Printable], selectedValue: Printable) {
self.title = title
self.array = array
self.selectedValue = selectedValue
}
}
The problem here is that the following error message appears on the selectedValue
declaration line:
Property cannot be marked dynamic because its type cannot be represented in Objective-C
If I go to the Xcode Issue Navigator, I can also read the following line:
Protocol 'Printable' is not '@objc'
Is there any workaround?