Error creating class reference and concatenating methods in Swift

0

Good evening.

I have two classes and I created an instance referencing the parent class by calling its method and it does not run and shows the following sentence:

"swift expressions are not allowed at the top level"

PS: I have tried everything, created it, recreated it ... they are all in the same group in Xcode

What can it be?

Follow print

    
asked by anonymous 14.01.2016 / 00:05

1 answer

1

The problem is that you are putting code to run directly at the top-level of the file, just as you would in languages like Python and JavaScript.

Swift, as well as C, C ++, Java, among others, only accepts code execution within functions. That is, lines 7 and 8 of your code must be within a function.

As you are programming for iOS, you can place any function in the application lifecycle, such as viewDidLoad and viewDidAppear.

    
14.01.2016 / 04:56