1

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"))
4

1 に答える 1

4

宣言のイニシャル+は、

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

Objective-Cのクラス メソッドです。インスタンスではなく、 クラス自体で呼び出す(またはSwift 言語で入力する)必要があります。

let encrypted = CustomObject.encrypt("p@$$w0rd", withKey: "12345678")
于 2015-10-15T05:59:27.633 に答える