答案 0 :(得分:2)
在swift项目中添加objective-c类时,系统会提示您输入
'创建桥接标题' - >点击'创建桥接头'。现在,您可以在swift中使用objective-c代码。
详细信息refer
根据您的问题修改解决方案:
//Objective-c class
// Test.h
#import <Foundation/Foundation.h>
@protocol TestDelegate <NSObject>
- (void)testMethod;
@end
@interface Test : NSObject
@property (weak, nonatomic) id<TestDelegate> delegate;
@end
//Test.m
#import "Test.h"
@implementation Test
@synthesize delegate;
- (void)callDelegate
{
[delegate testMethod];
}
@end
//Swift bridging header
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "Test.h"
//Swift class
class ViewController: UIViewController, TestDelegate {
.
.
.
func testMethod() {
print("Delegate");
}
}