目标文件
#import "EncryptionConstants.h"
@implementation EncryptionConstants
char encKey[] = "secretKey";
char iv[] = "secretIV";
@end
创建桥接文件后,我在一个 swift 文件中执行此操作..
var enc = EncryptionConstants()
print(enc.encKey)
出现如下错误:
value of EncryptionConstants has no member encKey.
最佳答案
头文件如下:
#import <Foundation/Foundation.h>
@interface EncryptionConstants: NSObject
@property unsigned char* encKey;
@property unsigned char* iv;
@end
.m 文件如下:
#import <Foundation/Foundation.h>
#import "EncryptionConstants.h"
@implementation EncryptionConstants
- (instancetype)init
{
self = [super init];
if (self) {
_encKey = "secretKey";
_iv = "secretIV";
}
return self;
}
@end
我们必须像下面这样快速调用:
let enc = EncryptionConstants()
print(String(cString: enc.encKey))
print(String(cString: enc.iv))
需要包含
#import "EncryptionConstants.h"
在你的桥接头中
关于objective-c - 在 Objective c .m 文件中声明一个 char 数据类型的字符串,并在 Swift 中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45728925/