随笔分类 -  swift

上一页 1 ··· 4 5 6 7 8
摘要:associatedtype关联类型 定义一个协议时,有的时候声明一个或多个关联类型作为协议定义的一部分将会非常有用。关联类型为协议中的某个类型提供了一个占位名(或者说别名),其代表的实际类型在协议被采纳时才会被指定。你可以通过 associatedtype 关键字来指定关联类型。比如使用协议声明更 阅读全文
posted @ 2018-05-28 22:41 zzfx 阅读(172) 评论(0) 推荐(0) 编辑
摘要:原文: Method Dispatch in Swift作者: Brain King译者: kemchenj 译者注: 之前看了很多关于 Swift 派发机制的内容, 但感觉没有一篇能够彻底讲清楚这件事情, 看完了这篇文章之后我对 Swift 的派发机制才建立起了初步的认知. 正文 一张表总结引用类 阅读全文
posted @ 2018-05-26 23:07 zzfx 阅读(985) 评论(0) 推荐(0) 编辑
摘要:Self相当于oc中的instance 是什么 相信大家都知道self这个关键字的具体作用,它跟OC里的self基本一样。但是对于Self来说...(WTF,这是什么东西) 当你用错Self的时候编译器会这样提示 'Self' is only available in a protocol or a 阅读全文
posted @ 2018-05-26 11:34 zzfx 阅读(592) 评论(0) 推荐(0) 编辑
摘要:Postfix Self Expression A postfix self expression consists of an expression or the name of a type, immediately followed by .self. It has the following 阅读全文
posted @ 2018-05-26 11:27 zzfx 阅读(228) 评论(0) 推荐(0) 编辑
摘要:dynamic Apply this modifier to any member of a class that can be represented by Objective-C. When you mark a member declaration with the dynamic modif 阅读全文
posted @ 2018-05-24 19:46 zzfx 阅读(1846) 评论(0) 推荐(0) 编辑
摘要:You write an in-out parameter by placing the inout keyword right before a parameter’s type. An in-out parameter has a value that is passed in to the f 阅读全文
posted @ 2018-05-23 19:09 zzfx 阅读(297) 评论(0) 推荐(0) 编辑
摘要:Written by Paul Hudson @twostraws It's very common in iOS to want to create complex objects only when you need them, largely because with limited comp 阅读全文
posted @ 2018-05-16 10:54 zzfx 阅读(161) 评论(0) 推荐(0) 编辑
摘要:'Self' is the type of a protocol/class/struct/enum.And the 'self' is a instance of a class/struct/enum.As for your requirement,maybe you could write l 阅读全文
posted @ 2018-05-15 19:26 zzfx 阅读(115) 评论(0) 推荐(0) 编辑
摘要:在 Swift 中能够表示 “任意” 这个概念的除了Any 、AnyObject以外,还有一个AnyClass。 Any、AnyObject、AnyClass有什么区别: 1.AnyObject 本身就是一个接口,而且所有的class都隐式的实现了这个接口,这也限制了AnyObject是只适用于Cl 阅读全文
posted @ 2018-05-14 12:55 zzfx 阅读(314) 评论(0) 推荐(0) 编辑
摘要:The features of Swift are designed to work together to create a language that is powerful, yet fun to use. Some additional features of Swift include: 阅读全文
posted @ 2018-05-07 19:48 zzfx 阅读(139) 评论(0) 推荐(0) 编辑
摘要:Swift 中的协议协议是为方法、属性等定义一套规范,没有具体的实现,类似于Java中的抽象接口,它只是描述了方法或属性的骨架,而不是实现。方法和属性实现还需要通过定义类,函数和枚举完成。 协议定义 // 协议定义通过关键字protocol protocol SomeProtocol { // 协议 阅读全文
posted @ 2018-04-08 16:27 zzfx 阅读(1257) 评论(0) 推荐(0) 编辑
摘要:1、oc比较: -(BOOL) isKindOfClass: classObj判断是否是这个类或者这个类的子类的实例 -(BOOL) isMemberOfClass: classObj 判断是否是这个类的实例 2、is 类型检查 Use the type check operator (is) to 阅读全文
posted @ 2018-04-08 11:47 zzfx 阅读(207) 评论(0) 推荐(0) 编辑
摘要:1、错误类型与枚举的结合 throw VendingMachineError.insufficientFunds(coinsNeeded: 5) throw VendingMachineError.insufficientFunds(coinsNeeded: 5) 2、异常捕获与栈展开 Error 阅读全文
posted @ 2018-04-08 11:23 zzfx 阅读(153) 评论(0) 推荐(0) 编辑
摘要:Swift defines two kinds of initializers for class types to help ensure all stored properties receive an initial value. These are known as designated i 阅读全文
posted @ 2018-04-04 16:41 zzfx 阅读(185) 评论(0) 推荐(0) 编辑
摘要:class UIViewSpringAnimator: SwipeAnimator { // 动画完成的闭包 var completion:((Bool) ->Void)? func addCompletion(completion:@escaping (Bool) ->Void) { self.c 阅读全文
posted @ 2018-04-04 15:53 zzfx 阅读(227) 评论(0) 推荐(0) 编辑
摘要:结论:value是拷贝,Reference是引用 Value and Reference Types Types in Swift fall into one of two categories: first, “value types”, where each instance keeps a u 阅读全文
posted @ 2018-04-03 19:28 zzfx 阅读(200) 评论(0) 推荐(0) 编辑
摘要:结论:1、optionals使用时需要检查;2、可以通过!+赋值语句转化为非optionals。 Optional-Generic Enumeration enum Optional<T> : LogicValue, Reflectable { case None case Some(T) init 阅读全文
posted @ 2018-04-03 16:21 zzfx 阅读(202) 评论(0) 推荐(0) 编辑
摘要:extension看起来很像一个匿名的category,但是extension和有名字的category几乎完全是两个东西。 extension在编译期决议,它就是类的一部分,在编译期和头文件里的@interface以及实现文件里的@implement一起形成一个完整的类,它伴随类的产生而产生,亦随 阅读全文
posted @ 2018-02-01 20:02 zzfx 阅读(117) 评论(0) 推荐(0) 编辑
摘要:https://developer.apple.com/swift/blog/?id=39 Increasing Performance by Reducing Dynamic Dispatch Like many other languages, Swift allows a class to o 阅读全文
posted @ 2017-07-15 23:31 zzfx 阅读(171) 评论(0) 推荐(0) 编辑

上一页 1 ··· 4 5 6 7 8