随笔分类 -  swift

摘要:VTables https://github.com/apple/swift/blob/master/docs/SIL.rst#vtables decl ::= sil-vtable sil-vtable ::= 'sil_vtable' identifier '{' sil-vtable-entr 阅读全文
posted @ 2018-09-20 17:48 zzfx 阅读(326) 评论(0) 推荐(0)
摘要:In this example: protocol MyProtocol { func testFuncA() } extension MyProtocol { func testFuncA() { print("MyProtocol's testFuncA") } } class MyClass 阅读全文
posted @ 2018-09-20 14:49 zzfx 阅读(164) 评论(0) 推荐(0)
摘要:Swift protocol extension method is called instead of method implemented in subclass protocol MyProtocol { func methodA() func methodB() } extension My 阅读全文
posted @ 2018-09-20 14:48 zzfx 阅读(135) 评论(0) 推荐(0)
摘要:1、v-table; class 2、WitnessTable protocol 3、消息派发。 @objc dynamic 阅读全文
posted @ 2018-09-20 11:51 zzfx 阅读(298) 评论(0) 推荐(0)
摘要:顶级修饰 次级修饰 赋值类型 存储类型 值类型 值类型 深拷贝 栈 值类型 引用类型 浅拷贝 堆 引用类型 值类型 浅拷贝 堆 引用类型 引用类型 浅拷贝 堆 复合引用类型会改变内部值类型的存储行为。 以上内容为推测 阅读全文
posted @ 2018-09-20 11:41 zzfx 阅读(286) 评论(0) 推荐(0)
摘要:两种参数传递方式 值类型 传递的是参数的一个副本,这样在调用参数的过程中不会影响原始数据。 引用类型 把参数本身引用(内存地址)传递过去,在调用的过程会影响原始数据。 在 Swift 众多数据类型中,只有 class 是引用类型,其余的如 Int、Float、Bool、Character、Array 阅读全文
posted @ 2018-09-20 11:04 zzfx 阅读(474) 评论(0) 推荐(0)
摘要:1、检查protocol本体是否声明调用函数; 2、如果没有,检查protocol扩展是否有该函数;如果扩展中也没有,报错; 3、如果本体声明了函数,使用动态派发机制进行派发;扩展中的实现位于最末位。 阅读全文
posted @ 2018-09-19 19:30 zzfx 阅读(192) 评论(0) 推荐(0)
摘要:We learned in the Protocol-Oriented Programming session at WWDC 2015 that Swift uses two different dispatch mechanisms for methods in protocol extensi 阅读全文
posted @ 2018-09-19 19:27 zzfx 阅读(176) 评论(0) 推荐(0)
摘要:引用类型 (Reference Type Matters) 引用的类型决定了派发的方式. 这很显而易见, 但也是决定性的差异. 一个比较常见的疑惑, 发生在一个协议拓展和类型拓展同时实现了同一个函数的时候. protocol MyProtocol { } struct MyStruct: MyPro 阅读全文
posted @ 2018-09-19 19:11 zzfx 阅读(263) 评论(0) 推荐(0)
摘要:@objc vs @objc dynamic @objc: Objective-C entry points One can explicitly write @objc on any Swift declaration that can be expressed in Objective-C. @ 阅读全文
posted @ 2018-09-19 18:17 zzfx 阅读(388) 评论(0) 推荐(0)
摘要:以NSObject为基类,只是为了提供Objective-C API的使用入口; 经由@object修改的对象,是这些api的参量。 NSObject是swift与oc特有机制沟通的桥梁。 Subclassing NSObject in Swift gets you Objective-C runt 阅读全文
posted @ 2018-09-19 17:47 zzfx 阅读(1433) 评论(0) 推荐(0)
摘要:Objective-C entry points https://github.com/apple/swift-evolution/blob/master/proposals/0160-objc-inference.md Before Swift 4, the compiler made some  阅读全文
posted @ 2018-09-19 17:30 zzfx 阅读(320) 评论(0) 推荐(0)
摘要:1、扩展中无法继承重写已有函数,不能添加函数。 Extensions can add new functionality to a type, but they cannot override existing functionality. https://docs.swift.org/swift- 阅读全文
posted @ 2018-09-19 16:47 zzfx 阅读(911) 评论(0) 推荐(0)
摘要:class 是引用类型,生成的实例分布在 Heap(堆) 内存区域上,在 Stack(栈)只存放着一个指向堆中实例的指针。因为考虑到引用类型的动态性和 ARC 的原因,class 类型实例需要有一块单独区域存储类型信息和引用计数。 在 Swift 中,class 类型的方法派发是通过 V-Table 阅读全文
posted @ 2018-09-19 15:13 zzfx 阅读(248) 评论(0) 推荐(0)
摘要:New operators are declared at a global level using the operator keyword, and are marked with the prefix, infix or postfix modifiers: prefix operator + 阅读全文
posted @ 2018-09-17 11:34 zzfx 阅读(199) 评论(0) 推荐(0)
摘要:precedencegroup ChainingPrecedence { associativity: left higherThan: TernaryPrecedence } infix operator >>- : ChainingPrecedence 重点在这: postfix operato 阅读全文
posted @ 2018-09-17 11:08 zzfx 阅读(161) 评论(0) 推荐(0)
摘要:只实现 getter 方法的属性被称为计算型属性,等同于 OC 中的 ReadOnly 属性 计算型属性本身不占用内存空间 不可以给计算型属性设置数值 计算型属性可以使用以下代码简写 计算型属性与懒加载的对比 计算型属性 不分配独立的存储空间保存计算结果 每次调用时都会被执行 更像一个函数,不过不能 阅读全文
posted @ 2018-09-14 19:52 zzfx 阅读(226) 评论(0) 推荐(0)
摘要:struct Stack<Element> { var items = [Element]() func push(_ item:Element){ self.items.append(item) } mutating func pop() -> Element{ return self.items 阅读全文
posted @ 2018-09-14 19:46 zzfx 阅读(444) 评论(0) 推荐(0)
摘要:In addition to stored properties, classes, structures, and enumerations can define computed properties, which do not actually store a value. Instead, 阅读全文
posted @ 2018-09-13 19:30 zzfx 阅读(160) 评论(0) 推荐(0)
摘要:与数据结合:对数据进行操作; 与行为结合:使用原有行为生成更便捷的行为; 与协议结合:实现协议; 与类型结合:对类型数据进行操作,添加新的行为; 与关联类型、泛型结合:对类型做出限定。 阅读全文
posted @ 2018-09-13 19:21 zzfx 阅读(274) 评论(0) 推荐(0)