将objc模块导入swift unclared类型

时间:2016-05-10 19:08:53

标签: objective-c swift

我想在swift中使用objc编写的库, 我的桥接头文件如下:

#ifndef my_Bridging_Header_h
#define my_Bridging_Header_h

#import "Pomelo.h"


#endif 

我已经在构建设置中添加了桥接文件的路径。

下面是Pomelo.h文件(你可以在这里找到整个库:https://github.com/NetEase/pomelo-iosclient):

//
//  Pomelo.h
//  iOS client for Pomelo
//
//  Created by Johnny on 12-12-11.
//  Copyright (c) 2012 netease pomelo team. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "SocketIO.h"

typedef void(^PomeloCallback)(id callback);

@class Pomelo;

@protocol PomeloDelegate <NSObject>
@optional
- (void)PomeloDidConnect:(Pomelo *)pomelo;
- (void)PomeloDidDisconnect:(Pomelo *)pomelo withError:(NSError *)error;
- (void)Pomelo:(Pomelo *)pomelo didReceiveMessage:(NSArray *)message;
@end

@interface Pomelo : NSObject <SocketIODelegate>
{

    __unsafe_unretained id<PomeloDelegate> _delegate;

    NSMutableDictionary *_callbacks;
    NSInteger _reqId;
    SocketIO *socketIO;
}

- (id)initWithDelegate:(id<PomeloDelegate>)delegate;
- (void)connectToHost:(NSString *)host onPort:(NSInteger)port;
- (void)connectToHost:(NSString *)host onPort:(NSInteger)port withCallback:(PomeloCallback)callback;
- (void)connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params;
- (void)disconnect;
- (void)disconnectWithCallback:(PomeloCallback)callback;

- (void)requestWithRoute:(NSString *)route andParams:(NSDictionary *)params andCallback:(PomeloCallback)callback;
- (void)notifyWithRoute:(NSString *)route andParams:(NSDictionary *)params;
- (void)onRoute:(NSString *)route withCallback:(PomeloCallback)callback;
- (void)offRoute:(NSString *)route;

@end

我写了一个模型swift文件:

import Foundation
//import Pomelo


class PomeloModel: NSObject, PomeloDelegate {
    @objc func Pomelo(pomelo: Pomelo!, didReceiveMessage message: [AnyObject]!) {

    }

    @objc func PomeloDidDisconnect(pomelo: Pomelo!, withError error: NSError!) {

    }

    @objc func PomeloDidConnect(pomelo: Pomelo!) {

    }

    func test() {
        let pomelo = Pomelo.init(delegate:self)
    }
}

但在课堂内,当我编译项目时,错误是: 使用未申报的类型:&#39; Pomelo&#39;。 我实际上是在尝试初始化一个Pomelo实例, 图书馆的原始文件说:

Pomelo *pomelo = [[Pomelo alloc] initWithDelegate:self];
[pomelo connectToHost:@"localhost" onPort:3000];

但是我无法正确启动Pomelo实例,任何人都可以帮助我吗?

0 个答案:

没有答案