我已經在一個swift項目中導入了這個Objective-C類。 MMLANSCanner.hinitWithDelegate for Objective-C類
#import <Foundation/Foundation.h>
@class Device;
@protocol MMLANScannerDelegate;
@protocol MMLANScannerDelegate <NSObject>
@required
- (void)lanScanDidFinishScanningWithStatus:(MMLanScannerStatus)status;
- (void)lanScanDidFailedToScan;
@optional
- (void)lanScanProgressPinged:(float)pingedHosts from:(NSInteger)overallHosts;
@end
#pragma mark - Public methods
@interface MMLANScanner : NSObject
-(instancetype)initWithDelegate:(id <MMLANScannerDelegate>)delegate;
@property(nonatomic,weak) id<MMLANScannerDelegate> delegate;
@property(nonatomic,assign,readonly)BOOL isScanning;
- (void)start;
- (void)stop;
@end
我成功創建了橋接報頭,使MainVC.Swift符合MMLANScannerDelegate。 然後我試着用代理self
初始化MMLanScanner。
import UIKit
import Foundation
class MainVC: UIViewController, MMLANScannerDelegate {
var presenter = MMLANScanner(delegate:self)
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func lanScanDidFindNewDevice(_ device: Device!) {
}
func lanScanDidFailedToScan() {
}
func lanScanDidFinishScanning(with status: MMLanScannerStatus) {
}
func lanScanProgressPinged(_ pingedHosts: Float, from overallHosts: Int) {
}
}
,但我得到的錯誤:
Argument passed to call that takes no arguments
任何想法如何實現initWithDelegate功能,我不得不在Objective-C?
你能解釋爲什麼downvote? – BlackM