This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIOffset { | |
/// 转换为 CGPoint 形式 | |
var point: CGPoint { | |
return CGPoint(x: horizontal, y: vertical) | |
} | |
} | |
extension CGPoint { | |
/// 转换为 UIOffset | |
var offset: UIOffset { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileprivate protocol _Optional { | |
func unwrappedString() -> String | |
} | |
extension Optional: _Optional { | |
fileprivate func unwrappedString() -> String { | |
switch self { | |
case .some(let wrapped as _Optional): return wrapped.unwrappedString() | |
case .some(let wrapped): return String(describing: wrapped) | |
case .none: return String(describing: self) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
// MARK: - FindHostView | |
protocol FindHostView { | |
associatedtype T | |
var hostView: T? { get } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - UIScrollViewDelegate | |
// 找到结束滚动事件 | |
func scrollViewDidEndDragging(_ sv: UIScrollView, willDecelerate decelerate: Bool) { | |
if !sv.isDragging, !sv.isDecelerating, !decelerate { | |
scrollViewDidEndScroll(sv) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. URL 转为 URLComponents 时,什么时候会变成 nil | |
// 2. URLComponents 转为 URL 时,什么时候会变成 nil | |
// 3. URL 协议后不带双斜杠时,为什么 host 会变成 path(如下例) | |
let str = "http:im.qq.com" // "mailto:[email protected]" | |
if let url = URL(string: str), let uc = URLComponents(url: url, resolvingAgainstBaseURL: true) { | |
print(url) | |
print(uc, uc.url!) | |
print(uc.scheme!, uc.path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 这两个方法有冲突(调用时无法区分),除非其中一个去掉IndexPath后的问号 | |
/// 不能有默认参数 nil,因为inout不能操作常量 | |
func shouldChange(indexPath: inout IndexPath?) -> Bool { | |
indexPath = IndexPath(item: 0, section: 1) | |
return true | |
} | |
/// 可以有默认参数 nil, | |
func shouldChange(indexPath: UnsafeMutablePointer<IndexPath?>? = nil) -> Bool { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension WKWebView { | |
/// sync version | |
/// | |
/// - Parameters: | |
/// - js: 要执行的javascript代码 | |
/// - timeout: 限时返回(单位秒),0表示不限时 | |
/// - Returns: 执行结果 | |
func evaluatingJavaScript(_ js: String, timeout: TimeInterval = 0) -> Any? { | |
var res: Any? = nil | |
var finish = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// textField included by a cell, and the cell included by a scrollView | |
override func willMove(toWindow newWindow: UIWindow?) { | |
super.willMove(toWindow: newWindow) | |
if newWindow == nil { | |
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillChangeFrame, object: nil) | |
} else { | |
NotificationCenter.default.addObserver(self, selector: #selector(keyboardFrameWillChange(_:)), name: .UIKeyboardWillChangeFrame, object: nil) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
po view.recersiveDescription 可以输出整个view层次 | |
po Thread.callStackSymbols 输出栈信息 |