加载中
swift基础之透明类型

透明类型 some 示例 protocol Shape { func draw() -> String } struct Triangle: Shape { var size: Int func draw() -> String { var result = [String]() for length in 1.......

04/21 14:43
0
swift基础之错误处理

错误处理 //错误处理 enum VendingMachineError: Error { case invalidSelection case insufficientFunds(coinsNeeded: Int) case outOfStock } struct Item { var price: Int var count: ....

swift基础之propertyWrapper

propertyWrapper示例 import SwiftUI @propertyWrapper struct UserDefaultsWrapper<T> { var key:String var defaultValue: T init(_ key: String, defaultValue: T) { se......

04/19 18:02
69
swift基础之swiftui中的动画

withAnimation import SwiftUI struct AnimationView: View { @State private var showDetail = false var body: some View { Button(action: { withAnimation{ ......

04/19 17:03
56
swift基础之swiftui

最终效果图 地图组件 MapView import SwiftUI import MapKit struct MapView: UIViewRepresentable { func makeUIView(context: Context) -> MKMapView { return MKMapView(frame: ....

04/19 16:06
96
swift基础之GCD

Grand Central Dispath(GCD) GCD是采用任务+队列的方式,有易用、效率高、性能好的特点 //concurrent 并行 let queue = DispatchQueue( label: "myQueue", qos: DispatchQoS.default, attri...

04/19 12:17
18
swift基础之线程Thread & Operation

Thread //Thread 原始方式 //Thread.detachNewThread 快捷方式创建Thread for i in 0...10 { Thread.detachNewThread{ print(i) } } /* 0 7 3 4 5 2 1 6 8 9 10 */ Thread.detach......

04/16 16:54
83
swift基础之泛型

泛型类型约束 //泛型类型约束 func findIndex(of valueToFind: T, in array: [T]) -> Int? { for (index, value) in array.enumerated() { if value == valueToFind { re......

04/16 15:43
41
swift基础之协议和扩展

协议 //协议 protocol Named { var name: String { get } } protocol Aged { var age: Int { get } } struct Person: Named, Aged { var name: String var age: Int } let p = Person(name:...

04/16 14:20
20
swift基础之扩展现有类、结构体、枚举

扩展计算属性 //扩展 Double 计算属性 extension Double { var km: Double { return self * 1_000.0 } var m: Double { return self } var cm: Double { return self / 100.0 } var mm: Dou...

04/16 11:08
61
swift基础之类多态

多态 //多态 class Media{ var name: String init(name: String) { self.name = name } func show() { print("name is (name)") } } class Movie: Media { ......

04/16 10:15
0
swift基础之类继承

基类 //基类 class Vehicle { var currentSpeed = 0.0 var description: String { return "traveling at (currentSpeed) miles per hour" } func makeNoise() { ......

04/16 09:24
0
swift基础之类的初始化和反初始化

类的初始化器 //类的初始化器 class Temperature { var number: Double let name: String init () { number = 20.0 name = "abc" } } 便捷初始化器convenience class Tem......

04/15 16:58
29
swift基础之类方法

类的实例方法 //类的实例方法 class Counter { var count = 0 func increment() { count += 1 } func increment(by count: Int) { self.count += count } ......

04/15 15:29
27
swift基础之类属性

延迟存储属性 lazy //延迟存储属性 lazy class DataImporter { var fileName = "data.txt" init() { print("DataImporter inits") } } class DataManager { lazy var importer = DataIm......

04/14 21:08
0
swift基础之枚举

枚举定义 //枚举定义 enum CompassPoint { case north case south case east case west } //常配合switch case使用 let directionToHead = CompassPoint.south switch directionToHead { ca...

04/13 11:51
26
swift基础之函数式编程

函数式编程 概念参考:函数式编程初探 示例 //统计词频 let non_words: Set = ["the", "and", "of", "to", "a", "i", "it", "in", "or", "is", "as", "so", "but", "be", "don't"] //常规方式...

swift基础之高阶函数

map let arr = [1,2,3,4] //map let mapRet = arr.map{ $0 * 2 } print(mapRet) //[2, 4, 6, 8] filter //filter let filterRet = arr.filter{ $0 % 2 == 0 } print(filterRet) //[2, 4] red...

04/12 16:27
24
swift基础之逃逸和自动闭包

逃逸闭包 当闭包作为一个实际参数传递给一个函数的时候,并且它会在函数返回之后调用,就说这个闭包逃逸了。常用在接收闭包实际参数来作为启动异步任务的回调。 自动闭包 是一种自动创建的用...

04/12 15:59
40
swift基础之函数

默认参数 func greet(_ person: String = "zhang san", _ hometown: String = "bei jing") -> String { return "Hello (person)! Glad you could visit from (hometown)" } print(greet()) /...

04/12 11:43
26

没有更多内容

加载失败,请刷新页面

返回顶部
顶部