Ios Swift 3-FTP上传
我已经将Rebekka touch框架添加到我的Swift 3项目中,以便通过FTP上传文件 我在xCode中使用了swift 3转换工具,只剩下一个错误 “NSMutableData”类型的值没有成员“count” 这里是它发生的地方:Ios Swift 3-FTP上传,ios,ftp,swift3,Ios,Ftp,Swift3,我已经将Rebekka touch框架添加到我的Swift 3项目中,以便通过FTP上传文件 我在xCode中使用了swift 3转换工具,只剩下一个错误 “NSMutableData”类型的值没有成员“count” 这里是它发生的地方: let bytes = self.inputData!.bytes.bindMemory(to: UInt8.self, capacity: self.inputData!.count) 全功能: override func streamEventEnd(_
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)
}
覆盖函数streamventend(uastream:Stream)->(Bool,NSError?){
var偏移量=0
让bytes=self.inputData!.bytes.bindMemory(收件人:UInt8.self,容量:self.inputData!.count)
让totalBytes=CFIndex(self.inputData!.length)
var parsedBytes=CFIndex(0)
let entity=unsafemeutablepointer.allocate(容量:1)
var resources=[ResourceItem]()
重复{
parsedBytes=CFFTPCreateParsedResourceListing(nil,bytes.advancedBy(offset),totalBytes-offset,entity)
如果parsedBytes>0{
let value=entity.pointee?.takeUnretainedValue()
如果让fptResource=value{
resources.append(self.mapFTPResources(fptResource))
}
偏移量+=已解析的数据字节
}
}当parsedBytes>0时
self.resources=资源
entity.deinitialize()
返回(真,无)
}
有人知道swift 3的等价物
self.inputData!。计数
?正如我在评论中所建议的那样。这项工作的长度,以及其他一些细微的变化如下:
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")
}
我用的是Swift3。
我对Rebekka框架的源代码做了以下更改,特别是ResourceListOperation.swift文件。(注:高级(按:…),.长度)
fileprivate var inputData:NSMutableData?
变量资源:[ResourceItem]?
覆盖函数streamventend(aStream:Stream)->(Bool,NSError?){
var偏移量=0
让bytes=self.inputData!.bytes.bindMemory(to:UInt8.self,容量:self.inputData!.length)
让totalBytes=CFIndex(self.inputData!.length)
var parsedBytes=CFIndex(0)
let entity=unsafemeutablepointer.allocate(容量:1)
var resources=[ResourceItem]()
重复{
parsedBytes=CFFTPCreateParsedResourceListing(nil,bytes.advanced(by:offset),totalBytes-offset,entity)
如果parsedBytes>0{
let value=entity.pointee?.takeUnretainedValue()
如果让fptResource=value{
resources.append(self.mapFTPResources(fptResource))
}
偏移量+=已解析的数据字节
}
}当parsedBytes>0时
self.resources=资源
entity.deinitialize()
返回(真,无)
}
以下是在导入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")
}
var配置=会话配置()
configuration.host=“”
configuration.username=“uname”
configuration.password=“password”
configuration.encoding=String.encoding.utf8
self.session=会话(配置:配置)
self.session.list(“/”){
(资源,错误)->中的Void
打印(“带有结果的列表目录:\n\(字符串(描述:资源)),错误:\(字符串(描述:错误))\n\n”)
}
self.inputData!怎么样!。长度?尝试使用.length
属性的数据
我现在正在尝试,我会更新问题,如果它有效是的,添加了一个答案
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")
}