相同點react
不一樣點swift
簡單使用數組
struct Size {
var width: Double = 0
var heigtht: Double = 0
func description() {
print("width:\(width) height:\(heigtht)")
}
}
class React {
var size = Size()
var area: Double {
get {
return size.width * size.heigtht
}
}
func description() {
print("size:\(size) area:\(area)")
}
}
var size = Size()
var react = React()
size.description()
react.description()
react.size.width = 10
react.size.heigtht = 15
react.description()
複製代碼
struct Size {
var width: Double = 0
var heigtht: Double = 0
func description() {
print("width:\(width) height:\(heigtht)")
}
}
class React {
var size = Size()
var area: Double {
get {
return size.width * size.heigtht
}
}
func description() {
print("size:\(size) area:\(area)")
}
}
var size = Size(width: 13, heigtht: 15)
size.description()
複製代碼
enum Num {
case one, two, three, four
}
var a = Num.one
var b = a
a = .three
if b == .one {
print("內存獨立")
}
複製代碼
struct Size {
var width: Double = 0
var heigtht: Double = 0
func description() {
print("width:\(width) height:\(heigtht)")
}
}
class React {
var size = Size()
var area: Double {
get {
return size.width * size.heigtht
}
}
func description() {
print("size:\(size) area:\(area)")
}
}
var size = Size(width: 13, heigtht: 15)
let size1 = size
size.width = 100
size1.description()
var react = React()
var react1 = react
react.size.width = 10
react.size.heigtht = 20
react1.description()
複製代碼
struct Size {
var width: Double = 0
var heigtht: Double = 0
func description() {
print("width:\(width) height:\(heigtht)")
}
}
class React {
var size = Size()
var area: Double {
get {
return size.width * size.heigtht
}
}
func description() {
print("size:\(size) area:\(area)")
}
}
var size = Size(width: 13, heigtht: 15)
let size1 = size
size.width = 100
size1.description()
var react = React()
var react1 = react
var react2 = React()
react.size.width = 10
react.size.heigtht = 20
react1.description()
if react1 === react {
print("react1 === react")
}else{
print("react1 !== react")
}
if react2 === react {
print("react2 === react")
}else{
print("react2 !== react")
}
複製代碼
類與結構體的選擇bash
swift中的值傳遞數據結構