Statements are not allowed on top level


I am very new to swift. I am trying to build an app that will help me translate English into a language I created.
I am able to write code, but I am not familiar with the syntax. Help me out here ?

i think you forgot about the singleWord declaration(var, let, blablabla).

if you’re just using singleWord as a loop counter, then use _.

if it’s a storyboard element, then link it.

I think you should use array.count and singleWord.count(if its an array) instead of array and singleWord in the for statement.

your FOR statement should be inside the IBAction from what i can see

it is also ideal to put all variables just above viewDidLoad(), including all IBOutlets

from what I can see, everything going from the line

var code = [

is outside the viewController.

all of the code from that line and below should be inside the ViewController class

“Statements are not allowed at the top level” means that statements like for are not allowed to be directly on the document, it must be in a declaration of a class or struct.

so basically you need to cut(command-x) all code below line 26, then create a new line by pressing enter at the end of line 24, and then pasting all the code from your clipboard(command-v)