随笔分类 -  swift

摘要:一般情况下Swit要想调用obj-c,c或c++代码必须通过obj-c以及桥接文件才可以办到,但是使用@_silgen_name,可以对于某些简单的代码,直接跳过桥接文件和.h头文件与C代码交互。 创建.c文件 #include <stdio.h> int add(int i, int j){ re 阅读全文
posted @ 2018-12-29 16:41 zzfx 阅读(439) 评论(0) 推荐(0) 编辑
摘要:func allItemsMatch<C1: Container, C2: Container> (_ someContainer: C1, _ anotherContainer: C2) -> Bool where C1.Item == C2.Item, C1.Item: Equatable { 阅读全文
posted @ 2018-12-13 16:52 zzfx 阅读(191) 评论(0) 推荐(0) 编辑
摘要:1、泛型定义本体有参量类型约束; 2、泛型扩展对参量类型约束; 3、函数参量约束; 泛型类型的访问控制: 1、与类型无关的通用函数,泛型的任何实例都可以访问; 2、与类型有关的函数(通过扩展约束实现),只有特定类型实例化的泛型实例才能访问; 由此得出结论: 再考虑泛型约束的情况下,泛型类型是一个代码 阅读全文
posted @ 2018-12-12 23:03 zzfx 阅读(282) 评论(0) 推荐(0) 编辑
摘要:1、泛型、泛型约束与扩展; 2、函数式编程; 3、值类型、引用类型; 4、枚举、关联值、元组等其他 上述为swift最大的特点 Another safety feature is that by default Swift objects can never be nil, and trying t 阅读全文
posted @ 2018-12-12 22:31 zzfx 阅读(762) 评论(0) 推荐(0) 编辑
摘要:具体化:针对特定的类型参量进行二次定义; 实例化:实例化; 阅读全文
posted @ 2018-12-12 19:39 zzfx 阅读(511) 评论(0) 推荐(0) 编辑
摘要:let firstHighScore = ("Mary", 9001)firstHighScore.0 firstHighScore.1 阅读全文
posted @ 2018-11-29 15:30 zzfx 阅读(106) 评论(0) 推荐(0) 编辑
摘要:协议的传统实现: 定义接口+实现协议 由抽象到具体; 协议的逆向实现(使用扩展): 由已存在的类型抽离部分功能作为协议,并让原体符合协议; 由具体到抽象; 向上抽离; 向上生成; 协议的缺省实现: (使用扩展)协议遵从的从无到有。 本质是协议于具体:先有谁,后有谁 及 怎么结合的问题; 协议的生成律 阅读全文
posted @ 2018-11-26 19:40 zzfx 阅读(317) 评论(0) 推荐(0) 编辑
摘要:swift的特性:扩展、协议、泛型 扩展与继承:对象的生长方式; 协议:支持 协议->类型、类型<-协议 的双向抽象; 泛型; 阅读全文
posted @ 2018-11-26 19:01 zzfx 阅读(225) 评论(0) 推荐(0) 编辑
摘要:相信大家都封装过网络层。 虽然系统提供的网络库以及一些著名的第三方网络库(AFNetworking, Alamofire)已经能满足各种 HTTP/HTTPS的网络请求,但直接在代码里用起来,终归是比较晦涩,不是那么的顺手。所以我们都会倾向于根据自己的实际需求,再封装一个更好用的网络层,加入一些特殊 阅读全文
posted @ 2018-11-26 17:55 zzfx 阅读(524) 评论(0) 推荐(0) 编辑
摘要:Attributes provide more information about a declaration or type. There are two kinds of attributes in Swift, those that apply to declarations and thos 阅读全文
posted @ 2018-11-14 19:17 zzfx 阅读(926) 评论(0) 推荐(0) 编辑
摘要:设计问题:谁来构造、构造什么、怎么添加新功能 关键词:本体、客体、构造、映射、功能。 别名:桥接变量、型变变量、容器变量、适配变量,构造变量; 目的:添加命名空间、添加新功能。 原则:不修改本体的实现。 原始版本: 在本体的扩展中,直接构造客体;客体的构造器输入参量为主体; 客体为具体类,直接完成本 阅读全文
posted @ 2018-11-07 18:02 zzfx 阅读(710) 评论(0) 推荐(0) 编辑
摘要:总结: 1、类型约束只能添加到泛型参量上面 2、关联类型是泛型参量; 3、关联类型可以通过 协议.关联类型名称的形式引用; func allItemsMatch<C1: Container, C2: Container> (_ someContainer: C1, _ anotherContaine 阅读全文
posted @ 2018-10-26 19:12 zzfx 阅读(1413) 评论(0) 推荐(0) 编辑
摘要:struct Degoo:Equatable { var lex:String var pex:String static func == (left:Degoo, right:Degoo) ->Bool{ return true } } func == (left:Degoo, right:Deg 阅读全文
posted @ 2018-10-26 15:50 zzfx 阅读(241) 评论(0) 推荐(0) 编辑
摘要:Starting from Swift 4.1, all you have to is to conform to the Equatable protocol without the need of implementing the == method. See: SE-0185 - Synthe 阅读全文
posted @ 2018-10-26 15:26 zzfx 阅读(882) 评论(0) 推荐(0) 编辑
摘要:Special Kinds of Methods Methods associated with a type rather than an instance of a type must be marked with the static declaration modifier for enum 阅读全文
posted @ 2018-10-26 15:19 zzfx 阅读(252) 评论(0) 推荐(0) 编辑
摘要:Operator Methods Classes and structures can provide their own implementations of existing operators. This is known as overloading the existing operato 阅读全文
posted @ 2018-10-26 12:56 zzfx 阅读(207) 评论(0) 推荐(0) 编辑
摘要:Shorthand Argument Names Swift automatically provides shorthand argument names to inline closures, which can be used to refer to the values of the clo 阅读全文
posted @ 2018-10-10 11:44 zzfx 阅读(229) 评论(0) 推荐(0) 编辑
摘要:Overview You can use Objective-C and Swift files together in a single project, no matter which language the project used originally. This makes creati 阅读全文
posted @ 2018-09-27 11:53 zzfx 阅读(201) 评论(0) 推荐(0) 编辑
摘要:Overview You can work with types declared in Swift from within the Objective-C code in your project by importing an Xcode-generated header file. This 阅读全文
posted @ 2018-09-27 11:51 zzfx 阅读(315) 评论(0) 推荐(0) 编辑
摘要:Objective-C没有命名空间,为了避免冲突,Objective-C的类型一般都会加上两到三个字母的前缀,比如Apple保留的NS和UI前缀,各个系统框架的前缀,各个系统框架的前缀SK(StoreKit),CG(CoreGraphic)等。 Swift的命名空间是基于module而不是在代码中显 阅读全文
posted @ 2018-09-26 20:01 zzfx 阅读(467) 评论(0) 推荐(0) 编辑