Error handling ';字符串';不符合协议';收集类型';Swift 2.0中的错误
我刚下载了XCode Beta 7,收到错误“Type'String'不符合协议'CollectionType'”。这是我第一次尝试编码,所以我不知道如何解决这个问题。谢谢你Error handling ';字符串';不符合协议';收集类型';Swift 2.0中的错误,error-handling,swift2,xcode7,Error Handling,Swift2,Xcode7,我刚下载了XCode Beta 7,收到错误“Type'String'不符合协议'CollectionType'”。这是我第一次尝试编码,所以我不知道如何解决这个问题。谢谢你 //the Pasteboard is nil if full access is not granted let pbWrapped: UIPasteboard? = UIPasteboard.generalPasteboard() if let pb = pbWrappe
//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)")
}
}
}
只是一个关于从哪里开始了解这个问题的建议。。。 Swift 2中的字符串将其更改为:
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)")
}
}
}
哪一行给出了错误?@PhillipMills if(count(type)>0)和&(image!=nil){请特别注意接受答案中有关Swift 2更改的注释。@PhillipMills,谢谢!但是,我对如何实现这一点仍然有点困惑(我是编写应用程序的新手,我几天前才开始学习)根据这个答案——我没有试过——建议是:
if(type.characters.count>0)&(image!=nil){
。