iOS app's connectivity with NetworkKit – a simple yet powerful network layer seamlessly integrating Combine Framework, Async/Await, and Unit Tests.
Checkout this sample project SwiftMVVMDemo.
public protocol NetworkHandler {
func fetch<T: Decodable>(request: Request) async throws -> T
func fetch<T: Decodable>(request: Request) -> AnyPublisher<T, RequestError>
}
import NetworkKit
class PostService: PostRetrievalService {
let networkManager: NetworkHandler
init(networkManager: NetworkHandler = NetworkManager()) {
self.networkManager = networkManager
}
func getPosts() async throws -> [Post] {
try await networkManager.fetch(request: PostRequest.getPosts)
}
}
Add NetworkKit
to your project using Swift Package Manager - https://github.com/rushisangani/NetworkKit
Feel free to submit issues or pull requests to enhance the functionality of NetworkKit.