is it ok to call closures in uikit uiviewcontroller from hosted swiftui view?

We cannot use [weak myCar] as myCar is a value type.

In the example from the article, myCar is a struct.

However, in your code:

contentView.buttonTapped = { [weak self] in
    self?.tappedButton()
}

self is a UIViewController which is a class (and a reference type).

Your use of [weak self] is perfectly fine: the closure will keep a weak reference to the UIViewController and when you tap a button, the tappedButton() function will be called. Which is probably what you expect.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top