Swift - Bridging标头失败。 ' *'没有名为' *'的成员

时间:2015-10-15 05:45:46

标签: ios objective-c swift

我开发了一个使用CommonCrypto库的应用程序。问题是我可以在Swift文件中创建一个实例。我的对象是使用Objective-C创建的。似乎无法很好地创建桥接头。

错误消息

/Users/MNurdin/Documents/iOS/xxxxx/Models/Main.swift:15:9: 'CustomObject' does not have a member named 'encrypt'

CustomObject.h

#import <Foundation/Foundation.h>
#import <CommonCrypto/CommonCrypto.h>
#import "GTMBase64.h"

@interface CustomObject : NSObject
+ (NSString*)encrypt:(NSString*)plainText withKey:(NSString*)key;
@end

CustomObject.m

#import "CustomObject.h"
@implementation CustomObject
+ (NSString*)encrypt:(NSString*)plainText withKey:(NSString*)key{
    /*--*/
    return result;
}
@end

Global.swift

var instanceOfCustomObject: CustomObject = CustomObject()
println(instanceOfCustomObject.encrypt("p@$$w0rd","12345678"))

1 个答案:

答案 0 :(得分:4)

声明中的初始+表示

+ (NSString*)encrypt:(NSString*)plainText withKey:(NSString*)key;

是Objective-C中的类方法。你必须把它叫做 class (或Swift语言中的 type )本身,而非实例:

let encrypted = CustomObject.encrypt("p@$$w0rd", withKey: "12345678")