-4
import UIKit

class MarksStruct {
    var mark: Int
    init(mark: Int) {
        self.mark = mark
    }
}

class studentMarks {
    var mark = 300
}

let marks = studentMarks()
print("Mark is \(marks.mark)")  //Expressions are not allowed at the top level

Anyone know why I get the error on the last line "Expressions are not allowed at the top level" and how do I fix it?

Valysar
  • 41
  • 2
  • 6

1 Answers1

4

Your code will work in the playground, but it can not work in a normal project. Move this code to a separate function and call it when needed.

let marks = studentMarks()
print("Mark is \(marks.mark)")
ViR
  • 276
  • 1
  • 3