iOS二次發育(swift)類

2022-08-18 18:57:14 字數 1836 閱讀 3271

類的初探

class

person

func

out() ->string

func goeast()

}let person = person(firstname: "

1", lastname: "2"

)person.

out()

person.firstname = "3"

;let person2 =person

person2.goeast()

person2.

out()

person === person2/*

引用同一塊位址

*/struct

location

}//值型別 方法改變自身,需宣告關鍵字mutating

//結構體

struct

location2}//

列舉enum

switch

}}var button =switch.off

button.click()

//

方法struct

point

struct

size

class

rectangle

//計算型屬性

varcenter:point

set }

}let rectangle = rectangle(point: point(x:10, y:20), size: size(width: 20, height: 20

))rectangle.center

rectangle.center = point(x: 1, y: 1

)rectangle.point

cgrect(x:

0, y: 0, width: 1, height: 1

)int.max

int.min

//類方法

struct

matrix

let row =arr2d.count

let col = arr2d[0

].count

for i in

1..}

self.m =arr2d

self.row =row

self.col =col

}func printmatrix()

print()}}

static func identitymatrix(n: int) -> matrix?

var arr2d: [[int]] =

for i in

0..return

matrix(arr2d)

}}if let m = matrix([[1, 2], [3,4

]])

if let m2 = matrix .identitymatrix(n: 4

) //

property observer 屬性觀察器

class

lightbulb

didset }}

}let lightbulb =lightbulb()

lightbulb.current = 10

lightbulb.current = 40

類的繼承

//

類方法用static關鍵字,無法繼承,所以要用class關鍵字

class

math

else

}}math.abs(number: -35

)class

submatn: math

}

iOS二次發育(swift)結構體

struct location else else else init latitude double,longitude double init?coordinatestring2 string guard let firstelement double coordinatestring2.sub...

15 二次封裝Response類

param data status 狀態碼 param msg 提示資訊 param results 附加資訊,如序列化得到的資料 param headers param status http狀態碼 param kwargs 其他資訊 data的初始狀態 狀態碼與狀態資訊 data data的響應...

tipask二次開發總結 tipask二次開發總結

條件模板 statement1 statement2 statement3 不帶下標變數的陣列迴圈 statement php的迴圈輸入 foreach array as value statement foreach array as key value 可以引用介面替換變數,其中必須為大寫字母,...