Skip to content

Instantly share code, notes, and snippets.

View johnhammerlund's full-sized avatar
🔨

John Hammerlund johnhammerlund

🔨
View GitHub Profile
/// SampleUITestDependencyFactoryIndex.swift
final class SampleUITestDependencyFactoryIndex: DependencyFactoryIndexable {
let index: [DependencyFactoryKey: (DependencyContainer) -> Any] = SampleUITestDependencyFactoryIndex.makeIndex()
private static func makeIndex() -> [DependencyFactoryKey: (DependencyContainer) -> Any] {
let foodServiceFactory: (DependencyContainer) -> Any = { _ in
let foodServiceStub = MockFoodService(food: MacAndCheese())
return foodServiceStub
}
import XCUITest
import Relay
final class SampleUITests: XCTestCase {
func testShowsFoodDetailScreen() {
let app = XCUIApplication()
let foodLaunchArgument = DependencyInstructionLaunchArgument(type: .foodService, factory: .foodFactoryWithMacAndCheese)
let drinkLaunchArgument = DependencyInstructionLaunchArgument(type: .drinkService, factory: .drinkFactoryWithAppleJuice)
import XCTest
final class KidTests: XCTestCase {
func testConsumesFoodAndDrink() {
let foodService = MockFoodService(food: macAndCheese)
let drinkService = MockDrinkService(drink: juice)
let kid = Kid()
kid.foodService = foodService
import Relay
public final class Kid {
@Injected var foodService: FoodService // Injected by DependencyContainer.global
@Injected var drinkService: DrinkService // Injected by DependencyContainer.global
func eatFood() {
let food = foodService.fetchFood()
let drink = drinkService.fetchDrink()
public final class Kid {
private let foodService: FoodService
private let drinkService: DrinkService
init(foodService: FoodService, drinkService: DrinkService) {
self.foodService = foodService
self.drinkService = drinkService
}
#!/usr/bin/env bash
check_references_corebluetooth() {
nm "$1" | grep "CBCentralManager" 2>&1 >/dev/null
}
find_usages () {
app_path=$1
if [[ ! -d $app_path || ! -d "$app_path/Frameworks" ]]; then
echo "$app_path is not a valid app directory."
@johnhammerlund
johnhammerlund / find-uiwebview-usages.sh
Created September 4, 2019 17:10
Searches for UIWebView symbols within an application binary and its embedded Frameworks
#!/usr/bin/env bash
#
# Usage: ./find-uiwebview-usages.sh <path1-to-.app> <path2-to-.app> <...>
check_references_uiwebview() {
nm "$1" | grep UIWeb 2>&1 >/dev/null
}
find_usages () {
app_path=$1
func registerDependencies() {
DependencyContainer.global.register(FoodService.self) { _ in
Pantry()
}
DependencyContainer.global.register(FoodService.self) { _ in
Refridgerator()
}
}
registerDependencies()
@johnhammerlund
johnhammerlund / dependency-injection-eli5.swift
Created February 2, 2019 19:40
Swift Dependency Injection - ELI5
/// ❌ Without dependency injection
public final class Kid {
private let fridge = Refridgerator()
func eatLunch() {
let food = fridge.fetchFood()
let drink = fridge.fetchDrink() /// POTENTIAL ERROR: Might be expired!
consume([food, drink])
#!/usr/bin/env bash
# Automatically installs swiftenv and run's swiftenv install.
# This script was designed for usage in CI systems.
git clone --depth 1 https://github.com/kylef/swiftenv.git ~/.swiftenv
export SWIFTENV_ROOT="$HOME/.swiftenv"
export PATH="$SWIFTENV_ROOT/bin:$SWIFTENV_ROOT/shims:$PATH"
if [ -f ".swift-version" ] || [ -n "$SWIFT_VERSION" ]; then
swiftenv install -s