上一页 1 ··· 53 54 55 56 57 58 59 60 61 ··· 103 下一页
摘要: 1、编译器只对确定类型进行检查; 2、类型转换是否能够成功有没有明确的判断;编译时or运行时; 3、任意类型不参与编译时类型检查; 任意类型不能直接参与运算,必须转化为确定的类型; 任意类型转化为确定类型是否需要显式转化。 强类型:类型检查(编译时)和转化(运行时)都有明确的状态信息; 中类型:类型 阅读全文
posted @ 2018-09-21 14:04 zzfx 阅读(260) 评论(0) 推荐(0)
摘要: 动态类型:变量的实际类型信息能够在在运行时(获取)确定;编译时不做类型检查。 弱类型:变量的类型信息能够在运行时改变。 阅读全文
posted @ 2018-09-21 12:56 zzfx 阅读(165) 评论(0) 推荐(0)
摘要: Swift Intermediate Language (SIL) https://github.com/apple/swift/blob/master/docs/SIL.rst#witness-method 阅读全文
posted @ 2018-09-20 17:59 zzfx 阅读(335) 评论(0) 推荐(0)
摘要: 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 阅读(325) 评论(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 阅读(134) 评论(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)
摘要: 运行时与动态是一个密切相关的概念: 动态加载; 动态类型识别; 动态派发; 内存管理; In the object-oriented programming languages, the runtime system was often also responsible for dynamic ty 阅读全文
posted @ 2018-09-20 11:06 zzfx 阅读(162) 评论(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 阅读(191) 评论(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 阅读(175) 评论(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 阅读(387) 评论(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 阅读(1432) 评论(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 阅读(319) 评论(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 阅读(909) 评论(0) 推荐(0)
摘要: Objective-C 的动态性是由 runtime 相关的库赋予的。 当然其他语言也完全可以运行在一个 Runtime 库上而获得动态性,由于多数高级语言的诞生都对应着一种编译器,因此将编译器的特性概括进语言里讲,也不是不可以。 http://www.cocoachina.com/ios/2016 阅读全文
posted @ 2018-09-19 16:01 zzfx 阅读(307) 评论(0) 推荐(0)
摘要: class 是引用类型,生成的实例分布在 Heap(堆) 内存区域上,在 Stack(栈)只存放着一个指向堆中实例的指针。因为考虑到引用类型的动态性和 ARC 的原因,class 类型实例需要有一块单独区域存储类型信息和引用计数。 在 Swift 中,class 类型的方法派发是通过 V-Table 阅读全文
posted @ 2018-09-19 15:13 zzfx 阅读(248) 评论(0) 推荐(0)
摘要: Normally, in a typed language, the dispatch mechanism will be performed based on the type of the arguments (most commonly based on the type of the rec 阅读全文
posted @ 2018-09-19 12:14 zzfx 阅读(300) 评论(0) 推荐(0)
上一页 1 ··· 53 54 55 56 57 58 59 60 61 ··· 103 下一页