2016-11-25 108 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") 
    }