Monday, January 23, 2017

Chapter 6 (Apple iOS programming): The Swift Programming Language

WIKI Article Swift_(programming_language)
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="">



//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())


 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.