随笔分类 - swift
摘要:1、泛型、泛型约束与扩展; 2、函数式编程; 3、值类型、引用类型; 4、枚举、关联值、元组等其他 上述为swift最大的特点 Another safety feature is that by default Swift objects can never be nil, and trying t
阅读全文
摘要:具体化:针对特定的类型参量进行二次定义; 实例化:实例化;
阅读全文
摘要:let firstHighScore = ("Mary", 9001)firstHighScore.0 firstHighScore.1
阅读全文
摘要:协议的传统实现: 定义接口+实现协议 由抽象到具体; 协议的逆向实现(使用扩展): 由已存在的类型抽离部分功能作为协议,并让原体符合协议; 由具体到抽象; 向上抽离; 向上生成; 协议的缺省实现: (使用扩展)协议遵从的从无到有。 本质是协议于具体:先有谁,后有谁 及 怎么结合的问题; 协议的生成律
阅读全文
摘要:swift的特性:扩展、协议、泛型 扩展与继承:对象的生长方式; 协议:支持 协议->类型、类型<-协议 的双向抽象; 泛型;
阅读全文
摘要:相信大家都封装过网络层。 虽然系统提供的网络库以及一些著名的第三方网络库(AFNetworking, Alamofire)已经能满足各种 HTTP/HTTPS的网络请求,但直接在代码里用起来,终归是比较晦涩,不是那么的顺手。所以我们都会倾向于根据自己的实际需求,再封装一个更好用的网络层,加入一些特殊
阅读全文
摘要:Attributes provide more information about a declaration or type. There are two kinds of attributes in Swift, those that apply to declarations and thos
阅读全文
摘要:设计问题:谁来构造、构造什么、怎么添加新功能 关键词:本体、客体、构造、映射、功能。 别名:桥接变量、型变变量、容器变量、适配变量,构造变量; 目的:添加命名空间、添加新功能。 原则:不修改本体的实现。 原始版本: 在本体的扩展中,直接构造客体;客体的构造器输入参量为主体; 客体为具体类,直接完成本
阅读全文
摘要:总结: 1、类型约束只能添加到泛型参量上面 2、关联类型是泛型参量; 3、关联类型可以通过 协议.关联类型名称的形式引用; func allItemsMatch<C1: Container, C2: Container> (_ someContainer: C1, _ anotherContaine
阅读全文
摘要:struct Degoo:Equatable { var lex:String var pex:String static func == (left:Degoo, right:Degoo) ->Bool{ return true } } func == (left:Degoo, right:Deg
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:Operator Methods Classes and structures can provide their own implementations of existing operators. This is known as overloading the existing operato
阅读全文
摘要:Shorthand Argument Names Swift automatically provides shorthand argument names to inline closures, which can be used to refer to the values of the clo
阅读全文
摘要: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
阅读全文
摘要:Objective-C没有命名空间,为了避免冲突,Objective-C的类型一般都会加上两到三个字母的前缀,比如Apple保留的NS和UI前缀,各个系统框架的前缀,各个系统框架的前缀SK(StoreKit),CG(CoreGraphic)等。 Swift的命名空间是基于module而不是在代码中显
阅读全文
摘要:Swift 的 extension 机制很强大,不仅可以针对自定义的类型,还能作用于系统库的类型,甚至基础类型比如 Int。当在对系统库做 extension 的时候,就会涉及到一个命名冲突的问题。Objective-C 时代的通行解决办法是在扩展方法名字的最前面加上 XXX_ 形式的前缀。这种形式
阅读全文
摘要:最近在看一些Swift开源库的时候,发现了一些优秀的开源库都使用了命名空间,例如Kingfisher这个开源库中,就针对UIImage,UIImageView,UIButton做了命名空间的扩展。通过logoImageView.kf.setImage(url)这种方式能够很好地避免扩展的命名冲突,而
阅读全文
摘要:class GooClass { deinit { print("aaaaaaaa") } var str = "gooClass" } struct GooStruct { var goo = GooClass() } extension ViewController{ var gooStruct
阅读全文
摘要:Swift Intermediate Language (SIL) https://github.com/apple/swift/blob/master/docs/SIL.rst#witness-method
阅读全文

浙公网安备 33010602011771号