作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已将 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/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!