A ready-to-push sample Network Layer for iOS using URLSession + async/await + Swift Concurrency with an optional Combine API. Includes a zero-internet mock server via URLProtocol and a demo SwiftUI view.
Built for iOS Labs community exercises. Plug-and-play with your TCA features.
- Clean
Endpointabstraction - Async/await
fetch+ Combinepublisher - Strong error typing (
APIError) - URLProtocol-based mock routing (no network required)
- Demo
ExampleViewto preview users + create post - TCA integration sketch (opt-in)
- Create a new iOS App (SwiftUI) project (iOS 16+).
- File > Add Packages⦠(optional) OR drag this folder into your project as a local package.
- Add
import NetworkLayerPOCin your app. - In your appβs root view, use the demo client:
import SwiftUI import NetworkLayerPOC @main struct DemoApp: App { var body: some Scene { WindowGroup { ExampleView() // uses mocked networking } } }
- Run. You should see two mock users and a button to create a post.
Use NetworkClientProtocol inside your reducer effects. See TCAUsersFeature.swift for a tiny example sketch (guarded with #if canImport(ComposableArchitecture)).
NetworkLayerPOC/
ββ Package.swift
ββ README.md
ββ LICENSE
ββ .gitignore
ββ Sources/
ββ NetworkLayerPOC/
ββ HTTPMethod.swift
ββ APIError.swift
ββ Endpoint.swift
ββ NetworkConfig.swift
ββ RequestBuilder.swift
ββ NetworkClient.swift
ββ Models.swift
ββ DummyAPI.swift
ββ MockURLProtocol.swift
ββ MockSessionFactory.swift
ββ Fixtures.swift
ββ MockRouting.swift
ββ ExampleUsage.swift
ββ ExampleView.swift
ββ TCAUsersFeature.swift
- This package compiles standalone, but
ExampleViewneeds SwiftUI (iOS/macOS). - Replace
mock.localwith your real base URL when connecting to live APIs and remove the mock protocol.
MIT