This file contains 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
override func viewWillAppear(animated: Bool) { | |
animateTable() | |
} | |
func animateTable() { | |
self.tableView.reloadData() | |
This file contains 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: - FlowLayout | |
private class FlowLayout: UICollectionViewFlowLayout, WaterfullFlowLayout { | |
var preparedLayoutAttributes: [UICollectionViewLayoutAttributes] = [] | |
override init() { | |
super.init() | |
callInit() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) |
This file contains 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
let page = Int(floor(($0.x - itemWidth / 2) / itemWidth) + 1) | |
pageControl.currentPage = page |
This file contains 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 UIScrollView { | |
//当UIScrollView滑动手势与 UIScreenEdgePanGestureRecognizer手势同在,手势沿响应链向下传递 | |
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool { | |
// 如果侧滑 Back 手势以及侧滑滚动手势同时响应,则调用 `open func require(toFail otherGestureRecognizer: UIGestureRecognizer)`使其侧滑滚动手势 failed | |
if gestureRecognizer is UIPanGestureRecognizer && otherGestureRecognizer is UIScreenEdgePanGestureRecognizer { | |
gestureRecognizer.require(toFail: otherGestureRecognizer) | |
// 允许手势沿响应链向下传递 | |
return true | |
} |
This file contains 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
#!/usr/bin/osascript | |
tell application "System Events" | |
repeat | |
if exists process "Safari" then | |
tell application "Safari" | |
activate | |
end tell | |
tell process "Safari" | |
keystroke "r" using {command down} |
This file contains 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 Foundation | |
import Alamofire | |
enum HTTPResult<Value> { | |
case success(Value) | |
case failure(Error) | |
} |
This file contains 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
public extension Decodable { | |
static func toModel(_ value: [String: Any], using decoder: JSONDecoder = JSONDecoder()) throws -> Self { | |
let data = try JSONSerialization.data(withJSONObject: value, options: JSONSerialization.WritingOptions.init(rawValue: 0)) | |
return try toModel(data, using: decoder) | |
} | |
static func toModel(_ value: [[String: Any]], using decoder: JSONDecoder = JSONDecoder()) throws -> [Self] { | |
let data = try JSONSerialization.data(withJSONObject: value, options: JSONSerialization.WritingOptions.init(rawValue: 0)) | |
return try toModel(data, using: decoder) | |
} |
This file contains 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
struct Model { | |
lazy var value: String = { | |
return text | |
}() | |
var myValue: String { | |
return value //error: Cannot use mutating getter on immutable value: 'self' is immutable | |
} | |
} |
This file contains 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
protocol Asable { | |
func `as`<T>(_ anyType: T.Type) -> T? | |
func `is`<T>(_ anyType: T.Type) -> Bool | |
} | |
extension Asable { | |
func `as`<T>(_ anyType: T.Type) -> T? { | |
return self as? T | |
} | |
func `is`<T>(_ anyType: T.Type) -> Bool { | |
return self is T |