swift compiler shows Expected declaration error? [duplicate]

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.

Leave a Comment