UIRefresh not working for my project?

So for my project it's a SwiftUI Project however if I Add '@objc' to expose this instance method to Objective-C it doesn't want it for some reason and the other error code is Argument of '#selector' refers to instance method 'refreshWebView' that is not exposed to Objective-C mainly this is the error I need to fix thanks in advance

this code is what's giving me the error

refreshControl.addTarget(self, action: #selector(refreshWebView(_:)), for: UIControl.Event.valueChanged)

this is for a pull to refresh the page

Could you post a complete sample code to test, not just a single line ?

here you go I sent it over from Mac to here simplified a little but the same thing

import SwiftUI
import WebKit

struct WkwebView: UIViewRepresentable {
let rc = UIRefreshControl()
let w =  WKWebView(frame: .zero, configuration: WKWebViewConfiguration())

func refreshWebView(_ sender: UIRefreshControl) {
        w.reload()
        sender.endRefreshing()
    }

func makeUIView(context: Context) -> WKWebView {
w.load(URLRequest(url: URL(string: "https://www.")!))

rc.addTarget(self, action: #selector(refreshWebView(_:)), for: UIControl.Event.valueChanged)

        w.scrollView.addSubview(rc)
        w.scrollView.bounces = true
} 

func updateUIView(_ uiView: WKWebView, context: UIViewRepresentableContext<WkwebView>) {
    }
}

Structs are not a thing in Objective-C hence why you cannot add @objc to your function.

The "real" solution is to use a Coordinator class to handle this (see makeCoordinator in the documentation.

Two other alternatives to consider:

  • Create a UIView with the WKWebView and selector inside, or
  • Subclass WKWebView and add both your refresh control and selector inside

The reason for your troubles is due to your SwiftUI "view" not really being a view, but a representation of what will become your view. The actual view that is rendered on screen may be a different instance. This is where the Coordinator comes in because it it persisted throughout your "view's" lifetime and passed between instances.

UIRefresh not working for my project?
 
 
Q