Objective c 在Objective c.m文件中声明一个具有char数据类型的字符串,并在Swift中使用它

Objective c 在Objective c.m文件中声明一个具有char数据类型的字符串,并在Swift中使用它,objective-c,swift,swift3,Objective C,Swift,Swift3,Objc文件 #import "EncryptionConstants.h" @implementation EncryptionConstants char encKey[] = "secretKey"; char iv[] = "secretIV"; @end 创建桥接文件后,我将在swift文件中执行此操作 var enc = EncryptionConstants() print(enc.encKey) 获取如下错误: EncryptionConst

Objc文件

#import "EncryptionConstants.h"

@implementation EncryptionConstants

 char encKey[] = "secretKey";
 char iv[] = "secretIV";

@end
创建桥接文件后,我将在swift文件中执行此操作

var enc = EncryptionConstants()
            print(enc.encKey)
获取如下错误:

EncryptionConstants的值没有成员密钥


头文件如下所示:

#import <Foundation/Foundation.h>

@interface EncryptionConstants: NSObject
@property unsigned char* encKey;
@property unsigned char* iv;

@end
需要包括

#import "EncryptionConstants.h"

在桥接头中

声明了一个静态变量。它只是修复了编译错误,但没有正确设置值。行警告_encKey=“secretKey”;将“char[10]”赋值为“unsigned char*”,可在指针之间转换为具有不同符号的整数类型。我们可以将char类型更改为nsstring。技术要求是,在charI更新了答案后,必须具有数据类型<代码>打印(字符串(cString:enc.encKey))打印(字符串(cString:enc.iv))请检查。
let enc = EncryptionConstants()
print(String(cString: enc.encKey))
print(String(cString: enc.iv))
#import "EncryptionConstants.h"