【周报】2020.02.24-2020.02.28

375 阅读1分钟

api

class func cancelPreviousPerformRequests(withTarget aTarget: Any)

在同一个 Runloop 里面,可以取消先前使用perform(_:with:afterDelay :)实例方法注册的执行请求。

func convert(_ rect: CGRect, to view: UIView?) -> CGRect

将指定的 rect 转换到目标 view 的坐标系中。

protocol

protocol ExpressibleByNilLiteral 

遵从 ExpressibleByNilLiteral 协议的类型可以用 nil 字面量来初始化。大多数类型并不遵从这个协议,因为用 Optional 来表示值可能不存在会更容易理解。但偶尔你也会碰到 ExpressibleByNilLiteral。

ExpressibleByNilLiteral 的指定构造方法不接收任何实际参数。(假设接收了,那结果会怎么样?)然而,该协议的指定构造方法不能仅仅只是一个空构造方法 init(),因为很多类型用它作为默认构造方法。

protocol CaseIterable 

可以获取 enum 所有的 case,直接看官方文档示例:

enum CompassDirection: CaseIterable {
    case north, south, east, west
}

print("There are \(CompassDirection.allCases.count) directions.")
// Prints "There are 4 directions."
let caseList = CompassDirection.allCases
                               .map({ "\($0)" })
                               .joined(separator: ", ")
// caseList == "north, south, east, west"

protocol RawRepresentable 

遵循这个协议的类型可以表示另一个类型,并且可以通过 rawValue 这个属性得到它表示的值。

bug

Instance method 'test()' nearly matches defaulted requirement 'test()' of protocol 'TestProtocol'

很奇怪,网上说是方法名写错了但和协议规定的方法名很像。但这里其实方法名是一模一样的,但还是出现了这个 warning,等修完再补充。

iOS 13 以后 modal 出来的卡片样式,距离屏幕顶部还有40的差距,导致控件被键盘遮住,解决方法暂时是把 modal 改成了 fullScreen 样式

link

Void

黃色警告 nearly matches optional requirement xxx of protocol xxx

谈谈 Swift 中的 RawRepresentable