Skip to content

Instantly share code, notes, and snippets.

View weAreJack's full-sized avatar
🏠
Working from home

Jack Smith weAreJack

🏠
Working from home
  • Manchester
View GitHub Profile
import SwiftUI
extension CGColor {
static let black = CGColor(red: 0, green: 0, blue: 0, alpha: 1)
static let white = CGColor(red: 1, green: 1, blue: 1, alpha: 1)
}
struct CodableColor: Codable {
static let black = CodableColor(cgColor: CGColor.black)
static let white = CodableColor(cgColor: CGColor.white)
@weAreJack
weAreJack / DynamicHeightVGrid.swift
Last active September 9, 2024 18:51
VGrid that allows dynamic height for items.
import SwiftUI
struct DynamicHeightVGrid: Layout {
var numberOfColumns: Int
var horizontalSpacing: CGFloat
var verticalSpacing: CGFloat
init(
numberOfColumns: Int = 2,
horizontalSpacing: CGFloat = 8,
import SwiftUI
struct SelfSizingSheet: ViewModifier {
@State private var height: CGFloat = .zero
private struct InnerHeightPreferenceKey: PreferenceKey {
static let defaultValue: CGFloat = .zero
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = nextValue()
}
@weAreJack
weAreJack / LoginPresenterTests.swift
Created October 2, 2020 12:08
DidLogInSuccessfullyCallsRouterTestExample
func testThatDidLogInSuccessfullyCallsRouterNavigateToHomeCalled() {
presenter.didLogInSuccessfully()
XCTAssertTrue(router.navigateToHomeCalled)
}
@weAreJack
weAreJack / LoginInteractorTests.swift
Created October 2, 2020 12:07
LogInRequestCallsPresenterTestExample
func testThatPerformLogInRequestCallsPresenterDidLogInSuccessfullyOnSuccess() {
interactor.username = "Valid Username"
interactor.password = "Valid Password"
interactor.performLogInRequest()
XCTAssertTrue(presenter.didLogInSuccessfullyCalled)
}
@weAreJack
weAreJack / LoginPresenterTests.swift
Created October 2, 2020 12:06
LogInTappedCallsInteractorTestExample
func testThatLogInTappedCallsInteractorPerformLogInRequest() {
presenter.logInTapped()
XCTAssertTrue(interactor.performLogInRequestCalled)
}
@weAreJack
weAreJack / LoginViewControllerTests.swift
Created October 2, 2020 12:05
LogInButtonTappedTestExample
func testThatLogInButtonTappedCallsPresenterLogInTapped() {
viewController.logInButtonTapped()
XCTAssertTrue(presenter.logInTappedCalled)
}
@weAreJack
weAreJack / MockLoginPresenter.swift
Created October 2, 2020 12:04
MockLoginPresenterExample
@testable import VIPER_Example
import Foundation
class MockLoginPresenter: LoginPresenterProtocol, LoginInteractorOutputProtocol {
// MARK: - LoginPresenterProtocol
var interactor: LoginInteractorInputProtocol?
// MARK: - Properties
@weAreJack
weAreJack / LoginProtocol.swift
Created October 2, 2020 12:04
LoginProtocolExample
import Foundation
// MARK: - View
/// Presenter -> ViewController
protocol LoginViewProtocol: AnyObject {
var presenter: LoginPresenterProtocol? { get set }
}
// MARK: - Interactor
/// Presenter -> Interactor
@weAreJack
weAreJack / LoginModule.swift
Created October 2, 2020 12:03
LoginModuleExample
import UIKit
class LoginModule {
func build() -> UIViewController {
let view = LoginViewController()
let router = LoginRouter()
let interactor = LoginInteractor()
let presenter = LoginPresenter(interface: view, interactor: interactor, router: router)
view.presenter = presenter