Mocking AsyncRequests with Factory
Mocking AsyncRequests with FactoryStrategies designed to make your network and service layer code easy to write, easy to test, and easy to preview.Michael Long ∙ May 7, 2025 ∙ 9 min read![]() ∙ View on Medium![]() You can't be a Swift developer without learning about protocols and their use in creating abstractions around common services. public protocol UserServiceType: Sendable { func load() async throws -> [User] } struct UserService: UserServiceType { @Injected(\.sessionManager) private var session public func load() async throws -> [User] { try await session.request() .add(path: "/api") .add(queryItems: ["results" : "25", "seed": "998", "nat": "us"]) .data(type: UserResultType.self) .results } } This example is using Factory to inject our session manager into our Continue reading This is a member-only story and can only be read on Medium. Sent to sikubaycom.s3cr3tz@blogger.com by Michael Long on Medium Unsubscribe from this newsletter or unsubscribe from all newsletters from Medium Manage your email settings 3500 South DuPont Highway, Suite IQ-101, Dover, DE 19901 Careers·Help Center·Privacy Policy·Terms of service |