ra1028 / SwiftUI-Combine

This is an example project of SwiftUI and Combine using GitHub API.
MIT License
451 stars 30 forks source link

Avatar Images are not loading #5

Open nagarajvrao opened 4 years ago

nagarajvrao commented 4 years ago

Simulator ios version - 13.4

nagarajvrao commented 4 years ago

Works fine without combine.

nagarajvrao commented 4 years ago

Is it because datataskpublisher returns anycancellable which calls cancel() when deinitialized. In our case, cancel() is called when control leaves fetchImage()

iHTCboy commented 3 years ago

@nagarajvrao so, how to fix it? -.-😂

ChiouBo commented 2 years ago

This is working for me

// Add anycancellable
private var subscription = Set<AnyCancellable>()

// Add .store(in: &Set<AnyCancellable>) after .sink
.sink(receiveValue: { [weak self] image in
                self?.userImages[user] = image
            }).store(in: &subscription)