How to resolve this problem: Expected '{' in body of Function declaration

Asked

Viewed 45 times

-2

I’m trying to print a hello world and I can’t. I actually put hello world in place of what I need to print to test and keeps giving the error.

import UIKit
import RealmSwift

class ForecastingViewController: UIViewController {

    @IBOutlet weak var fcstCreationDate: UILabel!
    @IBOutlet weak var fcstLastRun: UILabel!
    @IBOutlet weak var fcstUsedModel: UILabel!
    @IBOutlet weak var fcstNotes: UITextView!

    print("Hello World!")

I get the message Expected '{' in body of Function declaration on the print line.

  • Could put the full code?

1 answer

3


The call to the method print has to be made from within some method of its class:

class ForecastingViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        print("Hello World!")
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.