Swift - 桥接头失败。 “*”没有名为“*”的成员
Swift - Bridging header failed. '*' does not have a member named '*'
我开发了一个使用 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"))
声明中开头的+
表示
+ (NSString*)encrypt:(NSString*)plainText withKey:(NSString*)key;
是Objective-C中的class方法。你必须在
class(或 Swift 语言中的 type)本身,而不是实例:
let encrypted = CustomObject.encrypt("p@$$w0rd", withKey: "12345678")
我开发了一个使用 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"))
声明中开头的+
表示
+ (NSString*)encrypt:(NSString*)plainText withKey:(NSString*)key;
是Objective-C中的class方法。你必须在 class(或 Swift 语言中的 type)本身,而不是实例:
let encrypted = CustomObject.encrypt("p@$$w0rd", withKey: "12345678")