'self' 在 super.init 调用 swift 3.0 之前使用

'self' used before super.init call in swift 3.0

我有 OutputStream 的子 class。因为我有两个 init() 方法,一个有前缀词 convenience.

这是我的代码:

class FileOutputStream : OutputStream
{
      fileprivate let filepath:URL
      fileprivate let channel:DispatchIO!

      convenience init?(filename:String) {

           let pathURL = FileManager.default.urls(for: FileManager.SearchPathDirectory.documentDirectory, in:.userDomainMask).first!.appendingPathComponent(filename)
           self.init(filepath:pathURL)
      }

      init?(filepath f:URL) {

           self.filepath = f

           //if let path = f.path,
           if let cpath = (f.path).cString(using: String.Encoding.utf8) {

                let outputflag:Int32 = O_CREAT | O_WRONLY               // create, write-only
                let mode:mode_t = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH // permissions: u+rw, g+r, o+r
                self.channel = DispatchIO(type: DispatchIO.StreamType.stream, path:cpath, oflag:outputflag,mode: mode, queue: DispatchQueue.global(qos: DispatchQoS.QoSClass.background)) { (errcode:Int32) -> Void in

                     if errcode != 0 {
                          print("FileOutputStream: error creating io channel")
                     }
                 }
            }
            else {
               self.channel = nil
               return nil
            }
    }

    func write(_ string: String) {

        if let dataString = string.data(using: String.Encoding.utf8) {

            dataString.withUnsafeBytes {(bytes: UnsafePointer<UInt8>) -> Void in

                var data = DispatchData.empty
                data.append(bytes, count: dataString.count)

                    self.channel.write(offset: 0, data: data, queue: DispatchQueue.global(qos:.background), ioHandler: { (complete: Bool, data: DispatchData?, errorCode: Int32) in

                        //handle progress reporting here
                         if errorCode != 0 {
                            print("FileOutputStream: error writing data to channel")
                        }
                    })
                }
            }
        }

    deinit {

        self.channel.close(flags: DispatchIO.CloseFlags.stop)
    }
}

我遇到错误

'self' used before super.init call

我试过写

super.init() 

但仍然出现错误。有知道的请帮帮我

init?(filepath f:URL) 方法的末尾使用 super.init(url: f, append: false/true)

你的初始化器必须调用 super class 的指定初始化器..调用任何在 OutputStream class...

中可用的初始化方法
public init(toMemory: ())
public init(toBuffer buffer: UnsafeMutablePointer<UInt8>, capacity: Int)
@available(iOS 4.0, *)
public init?(url: URL, append shouldAppend: Bool)