gpt4 book ai didi

ios - Swift 3 - FTP 上传

转载 作者:行者123 更新时间:2023-11-29 11:51:46 27 4
gpt4 key购买 nike

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

我在 xCode 中使用了 swift 3 转换工具,但只剩下一个错误

Value of type 'NSMutableData' has no member 'count'

这是它发生的地方:

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 等价物吗?

最佳答案

我正在使用 Swift3。我在 Rebekka 框架的源代码中做了以下更改,特别是文件 ResourceListOperation.swift。 (注意:高级(by:..),.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")
}

关于ios - Swift 3 - FTP 上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40803147/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com