1. Variable
var (mutable)var age = 10let (immutable)
let name = "Capung"or with data type:
var age: Int = 10
let name: String = "Capung"
var isCool: Bool = true
let gender: Character = "M"
2. Print log
print()contoh:
print("Name: ")
print(name)
print("My Name is \(name)")
3. If condition
if age > 10 {
print("older than 10 years old")
} else {
print("child boy")
}
4. Function
Void/ without return datafunc calculate() {
let a = 2
let b = 2
print(a + b)
}
with return data type
func calculate() -> Int {
let a = 2
let b = 2
let c = 1
return a + b - c
}
with parameter
func calculate(a: Int, b: Int) {
print(a + b)
}
calculate(a: 1, b: 2)or
func calculate(_ a: Int, _ b: Int) {
print(a + b)
}
calculate(1, 2)
5. Class
class Animal {
let name: String = "Doggy"
var age: String = "12 Month"
func call() {
print("bark bark bark")
}
}
let Dog = Animal()
print(Animal.name)
Dog.call()
2018