不兼容的委托类型警告

时间:2013-02-04 20:21:57

标签: objective-c delegates

@interface Server : NSObject {
    id<ServerDelegate> _delegate;
    NSInputStream *_inputStream;
    NSOutputStream *_outputStream;
}

@property(nonatomic, assign) id<ServerDelegate> delegate;

每当我设置输入或输出流的委托时,我都会收到一条警告,指出它是从不兼容的类型Server *分配给id。

self.inputStream.delegate = self就是一个例子。

实际的服务器运行正常,这只是我担心的警告。

2 个答案:

答案 0 :(得分:1)

如果要将selfServer对象)指定为NSInputStream的委托,则Server对象必须符合NSStreamDelegate协议。< / p>

由于NSInputStreamNSStream

的子类

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSStream_Class/Reference/Reference.html#//apple_ref/occ/cl/NSStream

@interface Server : NSObject<NSStreamDelegate> 
[...]
@end

答案 1 :(得分:0)

您需要使Server类符合NSStreamDelegate:

@interface Server : NSObject <NSStreamDelegate> {
    ... var declarations
}