var floor = 1
for cinema in cinemas {
print("Floor: \(floor)")
floor += 1
for array in cinema {
for value in array {
print(value, terminator: " ")
}
print(" ")
}
print("-----------------")
}
// define a structure
struct Person {
// define two properties
var name = ""
var age = 0
}
// create instance of Person
var person1 = Person()
// access properties and assign new values
person1.age = 21
person1.name = "Rick"
print("Name: \(person1.name) and Age: \( person1.age) ")
class Enemy{
var health : Int = 100
var ATK : Int = 10
func walk(){
print("walked")
}
func copy()->Enemy{
let clone = Enemy()
clone.health = self.health
clone.ATK = self.ATK
return clone
}
}
let myOptional:String? = "hadoken"
// transform optional to actual variable (optional binding)
if let safeOptional = myOptional {
let text:String = safeOptional
print(text)
}
let myOptional:String? = nil
/*
nil coalescing operator
the passed value will be the optional value or a default if the optional
is a nil
*/
let text:String = myOptional ?? "it was a nil"
print(text) // prints it was a nil
struct MyOptionl{
var property = 1234
func method(){print("prints me")}
}
let myOptional: MyOptionl? = MyOptionl()
let text:Int = myOptional?.property ?? 25
print(text) // prints it was a nil
struct MyOptionl{
var property = 1234
func method(){print("prints me")}
}
let myOptional: MyOptionl? = MyOptionl()
// optional binding :
myOptional?.method() // (nil will not run)
/// Some introductory test that describes the purpose
/// of the function.
/**
What does this function do?
*/
func someFunction(name: String) -> Bool {
return false
}
/**
Another useful function
- parameters:
- alpha: Describe the alpha param
- beta: Describe the beta param
*/
func doSomething(alpha: String, beta: String) {
/**
Another useful function
- parameter alpha: Describe the alpha param
- parameter beta: Describe the beta param
*/
func doSomething(alpha: String, beta: String) {
/// Some introductory test that describes the purpose
/// of the function.
/// - Returns: true or false
func someFunction() throws -> Bool {
/// ---
/// # Subtitle 1
/// ## Subtitle 2
/// This is a *boring* list:
/// + First point
/// 1. subpoint with **bold text**
///
/// Some code - indented by four spaces
///
/// let flag = someFunction()
/// ---
/// seealso: [web site](url)