Skip to content

Instantly share code, notes, and snippets.

View aydin-emre's full-sized avatar

Emre AYDIN aydin-emre

View GitHub Profile
@aydin-emre
aydin-emre / TreeNode.swift
Created February 13, 2022 15:32
Tree Example on iOS, written in Swift..
import UIKit
public class TreeNode<T> {
public var value: T
public var children: [TreeNode] = []
public init(_ value: T) {
self.value = value
}
@aydin-emre
aydin-emre / Queue.swift
Created February 13, 2022 13:49
Queue Example on iOS, written in Swift..
import UIKit
public protocol Queue {
associatedtype Element
mutating func enqueue(_ element: Element)
mutating func dequeue() -> Element?
var isEmpty: Bool { get }
var peek: Element? { get }
}
@aydin-emre
aydin-emre / LinkedList.swift
Created February 10, 2022 12:42
LinkedList Example on iOS, written in Swift..
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
@aydin-emre
aydin-emre / Stack.swift
Created February 10, 2022 06:57
Stack Example on iOS, written in Swift..
import UIKit
public struct Stack<Element> {
private var storage: [Element] = []
public init() { }
public init(_ elements: [Element]) {
storage = elements
@aydin-emre
aydin-emre / NetworkManager.swift
Created February 3, 2022 10:12
Using SSL Pinning with Alamofire
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]
@aydin-emre
aydin-emre / NSURLSessionPinningDelegate.swift
Created February 3, 2022 10:08
Using URLSessionDelegate
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) {
@aydin-emre
aydin-emre / NetworkManager.swift
Created February 3, 2022 08:56
URLSession with configuration
session = URLSession(configuration: .default,
delegate: NSURLSessionPinningDelegate(),
delegateQueue: nil)
@aydin-emre
aydin-emre / NetworkManager.swift
Created February 3, 2022 08:55
URLSession.shared
session = URLSession.shared
@aydin-emre
aydin-emre / PassthroughSubject.swift
Created December 21, 2021 18:11
Custom PassthroughSubject, Publisher and Subscriber example
import Combine
enum MyError: Error {
case subscriberError
}
class StringSubscriber: Subscriber {
func receive(subscription: Subscription) {
subscription.request(.max(2))
@aydin-emre
aydin-emre / StringSubscriber.swift
Created December 21, 2021 14:25
Custom StringSubscriber, Publisher and Subscriber example
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