Closures and Capture Lists
Here’s the code if you want to experiment with it!
class ViewController: UIViewController {
let service = Service()
let formatter = Formatter()
let label = UILabel()
var cancellables = Set<AnyCancellable>()
override func viewDidLoad() {
super.viewDidLoad()
label.text = "Retrieved data: "
service.call().sink { [formatter, label] data in
let formatted = formatter.format(data: data)
label.text?.append(formatted)
}.store(in: &cancellables)
}
}