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 CFMessagesSocket: class { | |
| var delegate: CFMessagesSocketDelegate? { get set } | |
| func connect() | |
| func disconnect() | |
| func sendMessage(message: String) | |
| func sendMessage(data: Data) | |
| } |
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 CFMessagesSocket: class { | |
| var delegate: CFSocketClientDelegate? { get set } | |
| func connect() | |
| func disconnect() | |
| func sendMessage(message: String) | |
| func sendMessage(data: Data) | |
| } |
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
| var str = "Hello, playground" | |
| let url = URL(string: "http://www.example.com?skey=a72bzy321bgf&id=123123")! | |
| extension URL { | |
| var queryItemsDict: [String: String] { | |
| var dict = [String: String]() | |
| guard let urlComponents = URLComponents(url: self, resolvingAgainstBaseURL: false), let queryItems = urlComponents.queryItems else { return dict } | |
| for queryItem in queryItems { | |
| dict[queryItem.name] = queryItem.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
| enum Zero {} | |
| enum Add<T, U> { | |
| case inLeft(T) | |
| case inRight(U) | |
| } | |
| func fromTToAddTZero<T>(t: T) -> Add<T, Zero> { | |
| return .inLeft(t) |
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
| func request(to route: Route, completion: @escaping (Response?, Error?)) { | |
| ... | |
| } | |
| enum Result<T> { | |
| case success(T) | |
| case failure(Error) | |
| } | |
| func request1(to route: Route, completion: @escaping Result<Response>) { |
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. | |
| struct WorkDay { | |
| let numberOfClients: UInt8 | |
| let isWorkingDay: Bool | |
| } | |
| //2. | |
| (Bool, Bool) | |
| //3. |
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
| final class Loan { | |
| var expiryDate: String? | |
| var maturityDate: String? | |
| private var capitalStrategy: CapitalStrategy | |
| private init(capitalStrategy: CapitalStrategy) { | |
| self.capitalStrategy = capitalStrategy | |
| } | |
| static func termLoan() -> Loan { |
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 CapitalStrategy { | |
| func capital(loan: Loan) -> Double | |
| func riskFactor() -> Double | |
| } | |
| extension CapitalStrategy { | |
| func riskFactor() -> Double { | |
| return 0.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
| class Loan { | |
| var expiryDate: String? | |
| var maturityDate: String? | |
| func capital() -> Double { | |
| if expiryDate != nil && maturityDate != nil { | |
| return 10.0 * duration() * riskFactor() | |
| } | |
| if expiryDate != nil && maturityDate == nil { | |
| if getUnusedPercentage() > 1.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
| protocol OutputBuilder { | |
| func addElement(_ id: String) | |
| } | |
| class XMLBuilder: OutputBuilder { | |
| func addElement(_ id: String) {} | |
| } | |
| class DOMBuilder: OutputBuilder { | |
| func addElement(_ id: String) {} |