ios - How to println by swift in terminal? -


i'm trying run ./swift -emit-executable shape.swift terminal

shape.swift

class shape {     let name:string = ""      init(name:string)     {         self.name = name     }      let anyshape = shape.init(name:"jaum")     println("name, \(anyshape.name).") } 

i'm getting error:

shape.swift:11:5: error: expected declaration     println("name, \(anyshape.name).")     ^ 

what doing wrong?

you can't have declarations @ root level of class, move them outside.

don't use .init create class instance.

use print instead of println (it has changed in swift 2).

and don't give value of "" immutablename if want use initializer, declare type.

class shape {      let name:string      init(name:string) {         self.name = name     }  }  let anyshape = shape(name:"jaum")  print("name, \(anyshape.name).") 

last note, it's not swift swiftc able create executable:

swiftc -emit-executable shape.swift 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -