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 UIKit | |
public class TreeNode<T> { | |
public var value: T | |
public var children: [TreeNode] = [] | |
public init(_ value: T) { | |
self.value = value | |
} |
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 UIKit | |
public protocol Queue { | |
associatedtype Element | |
mutating func enqueue(_ element: Element) | |
mutating func dequeue() -> Element? | |
var isEmpty: Bool { get } | |
var peek: Element? { get } | |
} |
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 UIKit | |
public class Node<Value> { | |
public var value: Value | |
public var next: Node? | |
public init(value: Value, next: Node? = nil) { | |
self.value = value | |
self.next = next |
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 UIKit | |
public struct Stack<Element> { | |
private var storage: [Element] = [] | |
public init() { } | |
public init(_ elements: [Element]) { | |
storage = elements |
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 file_der = Bundle(for: type(of: self)).path(forResource: "easmart", ofType: "der") | |
let localCertificate = NSData(contentsOfFile: file_der!)! | |
let serverTrustPolicy = ServerTrustPolicy.pinCertificates( | |
certificates : [SecCertificateCreateWithData(nil, localCertificate)!], | |
validateCertificateChain : true, | |
validateHost : true | |
) | |
let serverTrustPolicies = ["easmart.co": serverTrustPolicy] |
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
class NSURLSessionPinningDelegate: NSObject, URLSessionDelegate { | |
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { | |
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust { | |
if let serverTrust = challenge.protectionSpace.serverTrust { | |
if #available(iOS 12.0, *) { | |
let isServerTrusted = SecTrustEvaluateWithError(serverTrust, nil) | |
if(isServerTrusted) { | |
if let serverCertificate = SecTrustGetCertificateAtIndex(serverTrust, 0) { |
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
session = URLSession(configuration: .default, | |
delegate: NSURLSessionPinningDelegate(), | |
delegateQueue: nil) |
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
session = URLSession.shared |
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 Combine | |
enum MyError: Error { | |
case subscriberError | |
} | |
class StringSubscriber: Subscriber { | |
func receive(subscription: Subscription) { | |
subscription.request(.max(2)) |
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
class StringSubscriber: Subscriber { | |
func receive(subscription: Subscription) { | |
print("Received: Subscription") | |
subscription.request(.max(23)) // backpressure | |
} | |
func receive(_ input: String) -> Subscribers.Demand { | |
print("Received: Value", input) | |
return .unlimited |
NewerOlder