IBM Swift Sandbox, online Swift compiler and execution
//my hello world/loop var str="Hello world!"; for i in 0..<10 i="" pre="" print="" str="">10>
//Rectangle Class example
import Foundation
class Rectangle {
var length = 0
var width = 0
init(length: Int, width: Int) { // Constructor
self.length = length
self.width = width
}
var Area: Int{
return length*width
}
func getArea() -> Int {
return length*width
}
}
let rect1 = Rectangle(length: 10, width: 10)
print(rect1.Area) // access the property
print(rect1.getArea())