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
| // Scanner | |
| extension Scanner { | |
| public struct Error: Swift.Error { | |
| let location: Int | |
| var localizedDescription: String { | |
| return "scan failure at location: \(location)" | |
| } | |
| } |
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
| enum Style { | |
| case none | |
| case bold | |
| case italic | |
| case boldItalic | |
| case sansSerif(bold: Bool, italic: Bool) | |
| case script(bold: Bool) | |
| case fraktur(bold: Bool) | |
| case doubleStruck | |
| case monospace |
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
| public enum BookingCode: String { | |
| case firstClass = "F" | |
| case businessClass = "J" | |
| case premiumEconomy = "W" | |
| case economy = "Y" | |
| } | |
| extension BookingCode: ExpressibleByStringLiteral { | |
| public init(stringLiteral value: String) { | |
| self.init(rawValue: value)! |
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 BehaviorRelay where Element: RangeReplaceableCollection { | |
| func acceptAppending(_ element: Element.Element) { | |
| accept(value + [element]) | |
| } | |
| } |
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
| @discardableResult | |
| func measure<A>(name: String = "", _ block: () -> A) -> A { | |
| let startTime = CACurrentMediaTime() | |
| let result = block() | |
| let timeElapsed = CACurrentMediaTime() - startTime | |
| print("Time: \(name) - \(timeElapsed)") | |
| return result | |
| } | |
| let result = measure { (0..<1_000_000).reduce(0, +) } |
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 <mach/mach_time.h> | |
| uint64_t start = mach_absolute_time(); | |
| // do stuff to be timed | |
| uint64_t end = mach_absolute_time(); | |
| uint64_t elapsed = end - start; | |
| mach_timebase_info_data_t info; |
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
| + (CGSize)rectForAttributedString:(NSAttributedString *)string | |
| size:(CGSize)theSize { | |
| if (!string || CGSizeEqualToSize(theSize, CGSizeZero)) { | |
| return CGSizeZero; | |
| } | |
| // setup TextKit stack | |
| NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:theSize]; | |
| NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:string]; | |
| NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init]; |
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
| let xCoord = 10 | |
| let yCoord = 20 | |
| let radius = 8 | |
| let dotPath = UIBezierPath(ovalInRect: CGRectMake(xCoord, yCoord, radius, radius)) | |
| let layer = CAShapeLayer() | |
| layer.path = dotPath.CGPath | |
| layer.strokeColor = UIColor.blueColor().CGColor |
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
| // | |
| // AYListStickyHeaderCollectionViewLayout.m | |
| // | |
| // | |
| // Created by anyuan on 30/11/2017. | |
| // | |
| #import "AYListStickyHeaderCollectionViewLayout.h" | |
| @implementation ListStickyHeaderCollectionViewLayout |
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 | |
| enum Result<T, E: Error> { | |
| case success(T) | |
| case failure(E) | |
| } | |
| extension Result { |
NewerOlder