Networking in SwiftUI | API Integration using Combine Framework | iOS Development | Display in List

preview_player
Показать описание
API integration using combine and SwiftUI
In this video i am calling the api using combine framework and displaying the data in the form of list using MVVM framework

Рекомендации по теме
Комментарии
Автор

You missed an important step. The subscriber in the view model must be stored in an AnyCancellable. This will keep around the subscriber until the view model is deallocated.

...
@Published var employeeData: [EmployeeDatum] = []

private var fetchCancellable: AnyCancellable?

func receiveEmployeeData() {
fetchCancellable = WebService.fetchApi()
.sink ....

davidhughes
Автор

I'm having Combine issues in Xcode 11.4 also, it's a different project but it keeps crashing. Bummer!

rgenericson
Автор

This code was giving following error:


This can be solved by creating a cancellable variable in view model class and storing the AnyPublisher returned by WebService

In ViewModel class add:
var cancellable: AnyCancellable?

And in the function receiveEmployeeData() change call to fetchApi as follows:

cancellable = WebService.fetchApi()

This solves the problem. The issue was the publisher was going out of scope even before the API received the response. This is avoided by storing the AnyPublisher in the ViewModel class property.

kulkarnipanku
Автор

one error solved...check ..github link

premcodes
visit shbcf.ru