swift fundamental

// var winners: Set<Int> = [3, 5, 8, 8]
var winners: Set = [3, 5, 8, 8]
print(winners)
// var winners: Set<Int> = [3, 5, 8, 8]
var winners: Set = [3, 5, 8, 8]

print(winners.contains(3))
winners.insert(10)
winners.remove(5)
print(winners)
print(winners.count)
let a: Set = [1, 3, 5, 8]
let b: Set = [3, 5, 8, 9]

print(a.union(b))
print(a.intersection(b))
print(a.union(b))
print(a.subtracting(b))

辞書

// var sales: Dictionary<String, Int> = ["kobayashi":200, "kudo":300]
// var sales = ["kobayashi": 200, "kudo": 300]
// sales["kudo"] =  500
// print(sales["kobayashi"] ?? "n.a.")
// sales["yushima"] = 400
// print(sales.count)

// for(key, value) in sales {
//     print("\(key): \(value)")
// }

let d = [String: Int]()
print(d.isEmpty)
[/code

関数

// func sayHi(){
//     print("hi")
// }
// sayHi()

func sayHi()-> String{
    return "hi"
}

print(sayHi())
// func sayHi(){
//     print("hi")
// }
// sayHi()

// func sayHi(name: String){
//     print("hi \(name)")
// }

// sayHi(name: "tom")


// func sayHi(from name: String){
//     print("hi \(name)")
// }

// sayHi(from: "tom")

// func sayHi(_ name: String){
//     print("hi \(name)")
// }

// sayHi("tom")

func sayHi(_ name: String = "tom"){
    print("hi \(name)")
}

sayHi()
func add10(x: inout Int){
    x = x + 10
    print(x)
}

var i = 10
add10(x: &i)

class

class User {
    let name: String // property
    var score: Int
    init(){
        self.name = "me!"
        self.score = 23
    }
    
}

// let uer: User = User()
let user = User()
print(user.name)
print(user.score)
user.score = 26
print(user.score)