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)
    }
}
Previous
Previous

for-loop vs filter()

Next
Next

Optionals vs Result