Skip to content

Instantly share code, notes, and snippets.

import UIKit
class MoveInOutViewController: UIViewController {
private weak var cardView: UIView!
private var cardViewHiddenConstraints: [NSLayoutConstraint]!
private var cardViewPresentConstraints: [NSLayoutConstraint]!
override func loadView() {
self.view = UIView()
@anuragajwani
anuragajwani / ProgressBarView.swift
Created October 18, 2020 21:31
Non-accessible progress bar view
import UIKit
class ProgressBarView: UIView {
var progress: CGFloat = 0.0 {
didSet {
self.setNeedsDisplay()
}
}
@anuragajwani
anuragajwani / order-testing-example-2.swift
Created May 3, 2020 17:39
iOS Dependecy Injection Swinject Ricardo respose
// use this in unit test target
class StubOrderValidator: OrderValidator {
var stubResponse: Bool!
func hasMinimumSpend(order: Order) -> Bool {
return self.stubResponse
}
}
@anuragajwani
anuragajwani / order-testing-example-1.swift
Created May 3, 2020 17:20
iOS Dependecy Injection Swinject Ricardo respose
struct Order {
var itemPrices: [Int]
}
protocol OrderValidator {
func hasMinimumSpend(order: Order) -> Bool
}
class OrderViewModel {
// Run in chrome console whilst on the stats page
function download(filename, text) {
var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
pom.setAttribute('download', filename);
if (document.createEvent) {
var event = document.createEvent('MouseEvents');
event.initEvent('click', true, true);
addUIInterruptionMonitor(withDescription: "Camera permission dialog") { (alert) -> Bool in
if alert.label == "“Application” Would Like to Access the Camera" {
alert.buttons["OK"].tap()
self.app.swipeUp()
self.app.swipeDown()
return true
}
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var appCoordinator: AppCoordinator!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
import Foundation
import UIKit
final class AppCoordinator {
private let navigationController: UINavigationController
private var childCoordinator: MoviesViewCoordinator!
init(navigationController: UINavigationController) {
import Foundation
import UIKit
final class MoviesViewCoordinator {
// MARK: - Instance dependencies
private let navigationController: UINavigationController
// MARK: - Instance state
private func convert(movies: [Movie]) -> MoviesViewModel {
let movieCellViewModels = movies.map { movie in
MovieCellViewModel(
textLabel: "\(movie.title) (\(movie.year))",
detailTextLabel: movie.genre.joined(separator: ", ")
)
}