我已经创建了一个NSInputStream子类,但是当它读取实际数据时,我得到以下异常。
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -setDelegate: only defined for abstract class. Define -[EventusCore.FileUploadStream setDelegate:]!'
我无法覆盖NSStream抽象类的以下属性:
unowned(unsafe) public var delegate: NSStreamDelegate?
这是我的继承自NSInputStream
的类class InputStream : NSInputStream {
private var currentStatus: NSStreamStatus = .Closed
// override var delegate: NSStreamDelegate?
weak var delegate: NSStreamDelegate?
override func open() {
self.currentStatus = .Open
}
override func close() {
self.currentStatus = .Closed
}
override var streamStatus: NSStreamStatus {
return self.currentStatus
}
override var hasBytesAvailable: Bool {
return self.currentStatus == .Open
}
// MARK: NSInputStream and CFReadStream abstract method overrides
override func scheduleInRunLoop(aRunLoop: NSRunLoop, forMode mode: String) {
}
override func removeFromRunLoop(aRunLoop: NSRunLoop, forMode mode: String) {
}
}
我做错了什么?这有可能使用Swift吗?
答案 0 :(得分:1)
找到一种合适的方法来覆盖委托变量
var localdelegate: NSStreamDelegate?
override var delegate: NSStreamDelegate? {
set {
self.localdelegate = newValue
}
get {
return self.localdelegate
}
}