A fully SwiftUI-based iOS networking layer with robust API handling, live image caching, and integrated Sentry logging for monitoring requests and errors. Designed to simplify API calls, provide detailed console logs, and handle errors gracefully.
- 📡 Async/Await Networking: Modern Swift concurrency support.
- 📦 Automatic JSON encoding/decoding: Uses
EncodableandDecodable. - 🚩 Error handling: Unified APIError mapping and logging.
- 📝 Sentry Integration: Logs API calls, responses, and errors for monitoring.
- 🏁 Pagination support: Efficiently loads more data when scrolling.
- 💿 Request caching: Handles offline scenarios automatically.
- 🖼 Image caching: Async image loading with in-memory caching.
Network-SwiftUI
│
├── Network/
│ │
│ ├── Core/
│ │ ├── API.swift # Defines API endpoints and request configurations
│ │ ├── Components.swift # Reusable networking components (headers, params, etc.)
│ │ ├── Generic.swift # Generic models or helpers for network responses
│ │ ├── Network.swift # Handles requests, response decoding, error mapping
│ │ └── NetworkImage.swift # Networking utilities specific to image downloading
│ │
│ ├── Extensions/
│ │ ├── Extensions.swift # Common Swift extensions used across the network layer
│ │ └── URLRequest.swift # Extension for building URLRequests & URLComponents
│ │
│ ├── Helpers/
│ │ ├── Connectivity.swift # Checks device's internet connection status
│ │ ├── Console.swift # Logs requests, responses, errors, and Sentry entry
│ │ └── Sentry.swift # API requests reporting / crash logging
│ │
│ └── UseCase/
│ ├── Repo.swift # Repository layer for data fetching & abstraction
│ └── Service.swift # Implementation of service calls for each endpoint
│
├── App/
├── Assets/
├── Scenes/
└── Etc...// View
struct ContentView: View {
var body: some View {
List(viewModel.list) { item in
// ...
}
.refreshable { Task { await viewModel.fetchExample() } }
.task { await viewModel.fetchExample() }
}
}// View Model
func fetchExample async {
let result = await repo.fetchExample(params: _)
switch result {
case .success(let response):
// ...
case .failure(let error):
// ...
}
}// Repository
class MyRepo: Repo {
func fetchExample(params: Param) async -> Result<BaseResponse<[Model]>, APIError> {
do {
let response: BaseResponse<[Model]> = try await network.call(Service.getExample(params))
return .success(response)
} catch {
return .failure(network.mapError(error))
}
}
}// Service
enum Service: ServiceProtocol {
case getExample(_ params: Param)
var url: String { API.baseUrl }
var path: String { "example" }
var method: HTTPMethod { .GET }
var parameters: Parameters? { params }
var headers: Headers? { nil }
var body: Encodable? { nil }
}All API calls, responses, and errors are automatically logged to Sentry via the SentryManager.
This provides full observability for networking in development environments.
- 🚀 API success/failure events
- 🕒 Request durations
- 📊 Statistics with chart
- 🐞 Errors and backend failure messages
- 📦 Response payloads
All network errors are mapped into APIError with types:
.url .request .network .parsing .unauthorized .server .backend .unknown
Use error.localize() to get a user-friendly localized string.

















