Skip to content

Instantly share code, notes, and snippets.

class Singleton {
static let shared: Singleton = {
let instance = Singleton()
// setup code
return instance
}()
}
class SomeSingletonClass {
static let shared: SomeSingletonClass = SomeSingletonClass()
private init() {}
func foo() {
}
}
@pallavtrivedi03
pallavtrivedi03 / SignupVC.swift
Created July 19, 2022 12:44
Dispatch Work Item code used in video - "Mastering Concurrency in iOS - Part 3"
import UIKit
import Combine
class SignupViewController: UIViewController {
@IBOutlet weak var signupLabel: UILabel!
@IBOutlet weak var errorLabel: UILabel!
@IBOutlet weak var usernameTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
private var cancellables = Set<AnyCancellable>()
@pallavtrivedi03
pallavtrivedi03 / SplashVC.swift
Created July 19, 2022 12:43
Dispatch Group code used in video "Mastering Concurrency in iOS - (Part 3)"
import UIKit
import Combine
class SplashViewController: UIViewController {
@IBOutlet weak var activityIndicator: UIActivityIndicatorView!
private var cancellables = Set<AnyCancellable>()
var launchDataDispatchGroup: DispatchGroup = DispatchGroup()
import Foundation
import Combine
class SignUpViewModel: ObservableObject {
@Published var userProfile: UserProfileModel?
private var cancellables = Set<AnyCancellable>()
func getOnboardingData() {
let publishers = Publishers.Zip(
import UIKit
import Combine
class ViewController: UIViewController {
@IBOutlet private var userNameTextField: UITextField!
@IBOutlet private var passwordTextField: UITextField!
@IBOutlet private var tncSwitch: UISwitch!
@IBOutlet private var signupButton: SignUpButton!
class AircraftView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
setupView()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupView()
}
class BoardingPassView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
setupView()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupView()
}
@pallavtrivedi03
pallavtrivedi03 / iOSCodeReviewChecklist.txt
Created September 18, 2021 16:50
A checklist for iOS Code Review.
iOS Code Review Checklist
Avoid Type Inference
Prefer using Higher Order Functions
Write DRY code (Don’t Repeat Yourself)
Make sure that there are no force unwraps
Make sure that there are no retain cycles
Check if any deprecated API is being used
Check if any hardcoded checks (generally strings) can be changed to enum.
Prefer enum, switch over if else.
@pallavtrivedi03
pallavtrivedi03 / CertificatePinning.swift
Created September 3, 2021 10:02
Implementation of SSL pinning (using certifcate)
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
guard let serverTrust = challenge.protectionSpace.serverTrust else {
completionHandler(.cancelAuthenticationChallenge, nil);
return
}
let certificate = SecTrustGetCertificateAtIndex(serverTrust, 0)
// SSL Policies for domain name check
let policy = NSMutableArray()