gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 06:13:45 25 4
gpt4 key购买 nike

目标文件

#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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com