2016-11-25 109 views
1

我已经将Rebekka触摸框架添加到我的Swift 3项目中,以便通过FTP上传文件。Swift 3 - FTP上传

我已经使用Xcode中迅速3转换工具,我只剩下一个错误

型“NSMutableData”的价值没有成员“计数”

这里的地方它发生:

let bytes = self.inputData!.bytes.bindMemory(to: UInt8.self, capacity: self.inputData!.count) 

全功能:

override func streamEventEnd(_ aStream: Stream) -> (Bool, NSError?) { 
    var offset = 0 
    let bytes = self.inputData!.bytes.bindMemory(to: UInt8.self, capacity: self.inputData!.count) 
    let totalBytes = CFIndex(self.inputData!.length) 
    var parsedBytes = CFIndex(0) 
    let entity = UnsafeMutablePointer<Unmanaged<CFDictionary>?>.allocate(capacity: 1) 
    var resources = [ResourceItem]() 
    repeat { 
     parsedBytes = CFFTPCreateParsedResourceListing(nil, bytes.advancedBy(offset), totalBytes - offset, entity) 
     if parsedBytes > 0 { 
      let value = entity.pointee?.takeUnretainedValue() 
      if let fptResource = value { 
       resources.append(self.mapFTPResources(fptResource)) 
      } 
      offset += parsedBytes 
     } 
    } while parsedBytes > 0 
    self.resources = resources 
    entity.deinitialize() 
    return (true, nil) 
} 

有没有人知道self.inputData!.count的swift 3等价物?

+2

怎么样'self.inputData。长度' –

+1

尝试使用'.length'属性'数据' –

+0

我正在尝试,现在我会更新问题,如果它工作 –

回答

0

正如我所用。长度得到这个工作,有如下一些其他的细微变化沿意见建议:

override func streamEventEnd(_ aStream: Stream) -> (Bool, NSError?) { 
    var offset = 0 
    let bytes = self.inputData!.bytes.bindMemory(to: UInt8.self, capacity: self.inputData!.count) 
    let totalBytes = CFIndex(self.inputData!.length) 
    var parsedBytes = CFIndex(0) 
    let entity = UnsafeMutablePointer<Unmanaged<CFDictionary>?>.allocate(capacity: 1) 
    var resources = [ResourceItem]() 
    repeat { 
     parsedBytes = CFFTPCreateParsedResourceListing(nil, bytes.advancedBy(offset), totalBytes - offset, entity) 
     if parsedBytes > 0 { 
      let value = entity.pointee?.takeUnretainedValue() 
      if let fptResource = value { 
       resources.append(self.mapFTPResources(fptResource)) 
      } 
      offset += parsedBytes 
     } 
    } while parsedBytes > 0 
    self.resources = resources 
    entity.deinitialize() 
    return (true, nil) 
} 

后来我追平使用触摸雷秸卡时的一些错误,示例使用没没有工作,所以我修改如下:

var configuration = SessionConfiguration() 
      configuration.host = "ftp.somewebsite.co.uk" 
      configuration.username = "username" 
      configuration.password = "password" 
      let URL = filename 
       let path = "/"+currentJob.ReservationsID+".png" 
       Session(configuration: configuration).upload(URL, path: path) { 
        (result, error) -> Void in 
        print("Upload file with result:\n\(result), error: \(error)\n\n") 

      } 
1

我正在使用Swift3。 我在Rebekka框架的源代码,特别是文件ResourceListOperation.swift中做了以下更改。 (注:高级(按:..),.length)。

fileprivate var inputData: NSMutableData? 
var resources: [ResourceItem]? 

override func streamEventEnd(_ aStream: Stream) -> (Bool, NSError?) { 
    var offset = 0 
    let bytes = self.inputData!.bytes.bindMemory(to: UInt8.self, capacity: self.inputData!.length) 
    let totalBytes = CFIndex(self.inputData!.length) 
    var parsedBytes = CFIndex(0) 
    let entity = UnsafeMutablePointer<Unmanaged<CFDictionary>?>.allocate(capacity: 1) 
    var resources = [ResourceItem]() 
    repeat { 
     parsedBytes = CFFTPCreateParsedResourceListing(nil, bytes.advanced(by: offset), totalBytes - offset, entity) 
     if parsedBytes > 0 { 
      let value = entity.pointee?.takeUnretainedValue() 
      if let fptResource = value { 
       resources.append(self.mapFTPResources(fptResource)) 
      } 
      offset += parsedBytes 
     } 
    } while parsedBytes > 0 
    self.resources = resources 
    entity.deinitialize() 
    return (true, nil) 
} 

以下是我在应用程序中使用进口RebekkaTouch框架后列出目录:!?

var configuration = SessionConfiguration() 
    configuration.host = "<ip-address:followed-by-port>" 
    configuration.username = "uname" 
    configuration.password = "password" 
    configuration.encoding = String.Encoding.utf8 
    self.session = Session(configuration: configuration) 
    self.session.list("/") { 
     (resources, error) -> Void in 
     print("List directory with result:\n\(String(describing: resources)), error: \(String(describing: error))\n\n") 
    }