var a = "0050"
var b = a
a = "2330"
print(b) // "0050"
// String 賦值是複製一份 String
func resetData(input: Int){
input = "" // Error 無法編譯,input 預設是 let
}
struct Stock{
var name: String = "0050"
}
var a = Stock()
var b = a
a.name = "2330"
print(b.name) // "0050"
// struct 賦值是複製一份 struct
func resetData(input: Stock){
input.name = "" // Error 無法編譯,input 預設是 let
}
class Stock{
var name: String = "0050"
}
var a = Stock()
var b = a
a.name = "2330"
print(b.name) // "2330"
// class 賦值是用同一份 class
func resetData(input: Stock){
input.name = "Null"
}
resetData(input: a)
print(a.name)
// class 傳值是用同一份 class,可以在方法內修改