随笔分类 - swift
摘要:在 Swift 中能够表示 “任意” 这个概念的除了Any 、AnyObject以外,还有一个AnyClass。 Any、AnyObject、AnyClass有什么区别: 1.AnyObject 本身就是一个接口,而且所有的class都隐式的实现了这个接口,这也限制了AnyObject是只适用于Cl
阅读全文
摘要: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:
阅读全文
摘要:Swift 中的协议协议是为方法、属性等定义一套规范,没有具体的实现,类似于Java中的抽象接口,它只是描述了方法或属性的骨架,而不是实现。方法和属性实现还需要通过定义类,函数和枚举完成。 协议定义 // 协议定义通过关键字protocol protocol SomeProtocol { // 协议
阅读全文
摘要:1、oc比较: -(BOOL) isKindOfClass: classObj判断是否是这个类或者这个类的子类的实例 -(BOOL) isMemberOfClass: classObj 判断是否是这个类的实例 2、is 类型检查 Use the type check operator (is) to
阅读全文
摘要:1、错误类型与枚举的结合 throw VendingMachineError.insufficientFunds(coinsNeeded: 5) throw VendingMachineError.insufficientFunds(coinsNeeded: 5) 2、异常捕获与栈展开 Error
阅读全文
摘要: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
阅读全文
摘要:class UIViewSpringAnimator: SwipeAnimator { // 动画完成的闭包 var completion:((Bool) ->Void)? func addCompletion(completion:@escaping (Bool) ->Void) { self.c
阅读全文
摘要:结论:value是拷贝,Reference是引用 Value and Reference Types Types in Swift fall into one of two categories: first, “value types”, where each instance keeps a u
阅读全文
摘要:结论:1、optionals使用时需要检查;2、可以通过!+赋值语句转化为非optionals。 Optional-Generic Enumeration enum Optional<T> : LogicValue, Reflectable { case None case Some(T) init
阅读全文
摘要:extension看起来很像一个匿名的category,但是extension和有名字的category几乎完全是两个东西。 extension在编译期决议,它就是类的一部分,在编译期和头文件里的@interface以及实现文件里的@implement一起形成一个完整的类,它伴随类的产生而产生,亦随
阅读全文
摘要:https://developer.apple.com/swift/blog/?id=39 Increasing Performance by Reducing Dynamic Dispatch Like many other languages, Swift allows a class to o
阅读全文

浙公网安备 33010602011771号