gpt4 book ai didi

error-handling - 'String' 不符合 Swift 2.0 中的协议(protocol) 'CollectionType' 错误

转载 作者:行者123 更新时间:2023-12-03 07:54:09 24 4
gpt4 key购买 nike

我刚刚下载了 XCode Beta 7 并收到错误“类型 'String' 不符合协议(protocol) 'CollectionType'”。这是我第一次尝试编码,所以我不知道如何解决这个问题。谢谢!!!

//the Pasteboard is nil if full access is not granted
let pbWrapped: UIPasteboard? = UIPasteboard.generalPasteboard()
if let pb = pbWrapped {
var type = UIPasteboardTypeListImage[0] as! String
if (count(type) > 0) && (image != nil) {
pb.setData(UIImagePNGRepresentation(image!)!, forPasteboardType: type)
var readDataWrapped: NSData? = pb.dataForPasteboardType(type)
if let readData = readDataWrapped {
var readImage = UIImage(data: readData, scale: 2)
print("\(image) == \(pb.image) == \(readImage)")
}
}
}

最佳答案

将其更改为:

type.characters.count

然后您的代码应为:
//the Pasteboard is nil if full access is not granted
let pbWrapped: UIPasteboard? = UIPasteboard.generalPasteboard()
if let pb = pbWrapped {
var type = UIPasteboardTypeListImage[0] as! String
if (type.characters.count > 0) && (image != nil) {
pb.setData(UIImagePNGRepresentation(image!)!, forPasteboardType: type)
var readDataWrapped: NSData? = pb.dataForPasteboardType(type)
if let readData = readDataWrapped {
var readImage = UIImage(data: readData, scale: 2)
print("\(image) == \(pb.image) == \(readImage)")
}
}
}

关于error-handling - 'String' 不符合 Swift 2.0 中的协议(protocol) 'CollectionType' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31657451/

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