How can I implement struct to inherit a protocol with <NSObject>

39 views Asked by At

I hava a UIKit sample code and want to convert to SwiftUI. There is a library in the UIKit sample that inherit a protocol with NSObject

class HomeViewController: BaseViewController, ScannerAcceptStatusListener, ScannerStatusListener, ScannerGot {

}

ScannerAcceptStatusListener


#import <Foundation/Foundation.h>

@class CommScanner;

@protocol ScannerAcceptStatusListener <NSObject>

- (void)OnScannerAppeared:(CommScanner *)scanner NS_SWIFT_NAME(OnScannerAppeared(scanner:));

@end

I try to convert it to SwfitUI and meet a error, enter image description here How should I do to listen the ScannerAcceptStatusListener protocol and where to implement the OnScannerAppered event?


struct InventoryView: View, ScannerAcceptStatusListener, ScannerStatusListener, ScannerGot  {
    @Binding var presentSideMenu: Bool
    
    var body: some View {
        VStack{
            HStack{
                Button{
                    presentSideMenu.toggle()
                } label: {
                    Image("menu")
                        .resizable()
                        .frame(width: 32, height: 32)
                }
                Spacer()
            }
            
            Spacer()
            Text("Inventory View")
            Spacer()
        }
        .padding(.horizontal, 24)
    }
}

Thank you, Zack

0

There are 0 answers