Swift 引用 OC 的类库
1、创建引用文件
/// {项目名称}-Bridging-Header.h
XQTest-Bridging-Header.h
2、创建OC类
@interface Auth : NSObject
@property(nonatomic, assign) NSInteger code;
@property(nonatomic, strong) NSString * name;
- (instancetype)initWithCode:(NSInteger) code name:(NSString *) name;
// NS_SWIFT_NAME 更接近 swift 的语法
- (void)insertUserWithCode:(NSInteger) code name:(NSString *) name NS_SWIFT_NAME(insertUser(code:name:));
+ (void)insertUserWithCode:(NSInteger) code name:(NSString *) name NS_SWIFT_NAME(insertUser(code:name:));
@end
3、引用OC类
在 “XQTest-Bridging-Header.h” 文件中
#import "Auth.h"
4、使用 Auth 类
var auth: Auth = Auth(code: 1001, name: "XQ_IT_MAN")
auth.insertUser(code: 1002, name: “XQ_IT”)
Auth.insertUser(code: 1003, name: “IT_MAN”)