Skip to content

Instantly share code, notes, and snippets.

@vani2
vani2 / SSL-pinning-example.swift
Last active Jun 27, 2021
SSL Pinning PK Example
View SSL-pinning-example.swift
override func urlSession(
_ session: URLSession,
didReceive challenge: URLAuthenticationChallenge,
completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
// 1
guard
challenge.protectionSpace.host == baseURL.host,
challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust,
let trust = challenge.protectionSpace.serverTrust
else {
View Protocol with associated type as Generic with inheritance.swift
import UIKit
protocol Presenter: AnyObject {
associatedtype T: VCLogic
var viewController: T? { get set }
}
protocol VCLogic: UIViewController {
func foo()
}
@vani2
vani2 / simulator_build.rb
Created Jan 14, 2021
Fastlane for app-file build
View simulator_build.rb
desc "Build simulator"
lane :build_simulator do
cocoapods
zip_path = "./#{app_target}.zip"
Dir.mktmpdir do |dir|
gym(
scheme: app_debug_scheme,
workspace: app_workspace,
View FetchImageOperationExample.swift
final class FetchImageOperation: AsyncOperation {
private(set) var result: Result<UIImage, Error>?
private lazy var imageProvider = ImageProvider()
private let imageID: String
init(imageID: String) {
self.imageID = imageID
super.init()
View AsyncOperation.swift
class AsyncOperation: Operation {
enum State: String {
case ready, executing, finished
fileprivate var keyPath: String {
return "is" + rawValue.capitalized
}
}
var state = State.ready {
willSet {
View ErrorHandling.swift
// Services Layer
final class EntityService: APIService, EntityServiceProtocol {
typealias EntityCompletion = (Result<Entity, Error>) -> Void
@discardableResult
func createEntity(_ entity: Entity, completion: @escaping EntityCompletion) -> Progress {
let endpoint = CreateEntityEndpoint(entity: entity)
return apiClient.request(endpoint, completionHandler: completion)
View SubprojectAppDelegate.swift
import UIKit
import Service
import Database
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
let user = Service().getUsers()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
View UsageService.swift
import UIKit
import Service
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
let user = Service().getUsers()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
View ServiceModule.swift
import Foundation
import Model
public class Service {
public init() {}
public func getUsers() -> [User] {
return [User(name: “Johny”)]
}
}
View PodfileWithService.rb
platform :iOS, ’13.0
use_frameworks!
target ‘ModuleExample’ do
end
target ‘Service’ do
pod ‘Model’, :path => ‘Model’
end