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
| // Before | |
| let start = 10 | |
| var i = start | |
| while i < 5 { | |
| // do something | |
| i += 1 | |
| } | |
| // After |
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 Signal { | |
| func observeUI() -> Signal<Value, Error> { | |
| return observe(on: UIScheduler()) | |
| } | |
| } | |
| extension SignalProducer { | |
| func observeUI() -> SignalProducer<Value, Error> { | |
| return lift { $0.observeUI() } | |
| } |
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
| class TVPodcastFlowLayout: UICollectionViewFlowLayout { | |
| override func prepare() { | |
| super.prepare() | |
| register(TVCollectionReusableView.self, forDecorationViewOfKind: TVCollectionReusableView.identifier) | |
| } | |
| override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { | |
| let attributes = super.layoutAttributesForElements(in: rect) | |
| var allAttributes = attributes |
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 | |
| extension UITableView | |
| { | |
| // MARK: - Registering Cell Types | |
| /// Yields the built-in reuse identifier for the specified cell type. | |
| /// | |
| /// - parameter cellType: The cell type. | |
| private func reuseIdentifier<T: UITableViewCell>(cellType: T.Type) -> String | |
| { |
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
| // http://swift.gg/2015/10/27/swift-pattern-matching-in-detail/ | |
| // 遍历目录 | |
| guard let enumerator = NSFileManager.defaultManager().enumeratorAtPath("/customers/2014/") | |
| else { return } | |
| for url in enumerator { | |
| switch (url.pathComponents, url.pathExtension) { |
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 Foundation | |
| extension Indexable { | |
| subscript(safeIndex safeIndex: Index) -> _Element? { | |
| return safeIndex.distance(to: endIndex) > 0 ? self[safeIndex] : 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
| struct Stock { | |
| var name = "" | |
| var id = "" | |
| } | |
| let stock1 = Stock(name: "name", id: "1") | |
| let stock2 = Stock(name: "name", id: "2") | |
| let stock3 = Stock(name: "name", id: "3") | |
| let stock4 = Stock(name: "name", id: "4") | |
| let stock5 = Stock(name: "name", id: "5") |
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
| // http://www.futantan.com/2016/04/14/NSTimer-tips/#more | |
| extension NSTimer { | |
| private class FTTimerClosureWraper { | |
| private (set) var timerClosure: () -> () | |
| init(timerClosure: () -> () ) { | |
| self.timerClosure = timerClosure | |
| } | |
| } |
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 Foundation | |
| typealias JSONDict = [String: Any] | |
| struct Parameter<A> { | |
| let apiDescription: String | |
| let parse: (Any) -> A? | |
| } | |
| extension Parameter { |
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 Foundation | |
| import Dispatch | |
| import PlaygroundSupport | |
| PlaygroundPage.current.needsIndefiniteExecution = true | |
| precedencegroup Additive { | |
| associativity: left | |
| } |
OlderNewer