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 | |
| struct Regex { | |
| let pattern: String | |
| } | |
| protocol RegexMatchable : StringProtocol { | |
| var regex: Regex { get } | |
| func matches(regex: Regex, options: NSRegularExpression.Options) -> [String] | |
| func capturedGroups(regex: Regex, options: NSRegularExpression.Options) -> [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
| import Foundation | |
| protocol Network { | |
| typealias SuccessHandler = (Array<Response>) -> Void | |
| associatedtype Response: Codable | |
| var payloads: Array<Response> { get } | |
| func fire(onSuccess: SuccessHandler) | |
| } |
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 NSRegularExpression { | |
| convenience init(_ pattern: String) { | |
| do { | |
| try self.init(pattern: pattern) | |
| } catch { | |
| preconditionFailure("Illeagal regular expression: \(pattern).") | |
| } |
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 | |
| // case name must same as Asset Name | |
| enum ImageAsset: CaseNameConvertible, CaseIterable { | |
| case logoEN, logoZH | |
| case msgTrash, msgChecked, msgUnchecked | |
| case navbarClose, navbarBack | |
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 | |
| class BaseViewController { | |
| var basicProperty: Int { | |
| return 10 | |
| } | |
| required init(coder: NSCoder) { | |
| fatalError() |
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
| // | |
| // ViewController.swift | |
| // GenericViewController | |
| // | |
| // Created by 陳 冠禎 on 16/04/2018. | |
| // Copyright © 2018 AppCoda. All rights reserved. | |
| // | |
| import UIKit |
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
| protocol EnumCollection : Hashable { | |
| static var allCases: [Self] { get } | |
| } | |
| extension EnumCollection { | |
| static var allCases: [Self] { | |
| let anySequence = AnySequence { () -> AnyIterator<Self> in | |
| var index = 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 UIKit | |
| protocol CellConfigurable: RawRepresentable { | |
| init(indexPath: IndexPath) | |
| } | |
| extension RawRepresentable where Self.RawValue == Int { | |
| static var allCases: [Self] { return allCases() } | |
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 | |
| // Source: http://www.lintcode.com/en/problem/reverse-order-storage/ | |
| // Question: Given 1 -> 2 -> 3 -> null, return [3,2,1]. | |
| extension Collection { | |
| func generatorLinkList(inital: inout LinkedListNode<Element>) { | |
| reduce(into: inital) { | |
| $0.nextNode = LinkedListNode(value: $1) | |
| $0 = $0.nextNode! | |
| } | |
| } |
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 | |
| //1 -> 2 -> 3 [3,2,1] | |
| protocol LinkListable { | |
| associatedtype Value | |
| var value: Value { get } | |
| var reference: Self? { get } | |
| } | |