When this code is written in AllListViewController
and run, the compiler shows the Expected Declaration error:
for list in lists{ let item = ChecklistItems() item.text = "Item for \(list.name))" list.items.append(item) }
I think you have the code in the wrong place in the class same like this question.
so move it to any function or in viewDidLoad
method.
Hope it will help.
You have the code like below image:
Seems like Your code is outside the function. If allListViewController
is your UIViewController
class where the for
loop code is written make sure the code should be inside the body of any function of allListViewController
class. It can not be outside.
Example:
override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. for list in lists{ let item = ChecklistItems() item.text = "Item for (list.name))" list.items.append(item) } }
You can just initialise/declare the variables (will be global variables) outside the function body.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With