This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
final class KidTests: XCTestCase { | |
func testConsumesFoodAndDrink() { | |
let foodService = MockFoodService(food: macAndCheese) | |
let drinkService = MockDrinkService(drink: juice) | |
let kid = Kid() | |
kid.foodService = foodService |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Kid { | |
private let foodService: FoodService | |
private let drinkService: DrinkService | |
init(foodService: FoodService, drinkService: DrinkService) { | |
self.foodService = foodService | |
self.drinkService = drinkService | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func registerDependencies() { | |
DependencyContainer.global.register(FoodService.self) { _ in | |
Pantry() | |
} | |
DependencyContainer.global.register(FoodService.self) { _ in | |
Refridgerator() | |
} | |
} | |
registerDependencies() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// ❌ 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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
NewerOlder