The compiler throws an error when trying to assign a new value:
Cannot assign to immutable expression of type 'Bool?'
I have a class:
class Setting { struct Item { var text: String var selected: Bool? init(withText text: String) { self.text = text self.selected = nil } var items: Any init(items:Any) { self.items = items } }
In the source view controller in prepareForSegue :
let item = Setting.Item(withText: user.description) let setting = Setting(items: [item]) destinationViewController.setting = setting
In view view controller:
class DestinationViewController: UITableViewController { var setting: Setting! override func viewDidLoad() { super.viewDidLoad()
I declared the items as "Any" because it can contain [Items] or [[Items]].
How to make the selected variable mutable?
(I hope this is not a duplicate question, I found many similar questions, but could not solve it.)
immutability swift
Manuel
source share