gpt4 book ai didi

xcode - 类型 'AnyObject' 不符合协议(protocol) 'SequenceType'

转载 作者:IT王子 更新时间:2023-10-29 05:09:04 24 4
gpt4 key购买 nike

func loadThumbnails() {

let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
let documentsDirectory:NSString = paths[0] as NSString
var error:NSError?
let fileManager = NSFileManager()
let directoryContent:AnyObject = fileManager.contentsOfDirectoryAtPath(documentsDirectory, error: &error)!

thumbnails = [QSPhotoInfo]()

for item:AnyObject in directoryContent {
let fileName = item as NSString
if fileName.hasPrefix(kThumbnailImagePrefix) {
let image = loadImageFromDocumentsDirectory(fileName)
var photoInfo = QSPhotoInfo()
photoInfo.thumbnail = image;
photoInfo.thumbnailFileName = fileName
thumbnails += photoInfo
}
}
}

编译错误如下:

Type 'AnyObject' does not conform to protocol 'SequenceType'

这是什么意思?

谁能帮帮我,非常感谢!!!

最佳答案

Apple 在 The Swift Programming Language 中声明:

The for-in loop performs a set of statements for each item in a range, sequence, collection, or progression.

目前,directoryContent 仅符合协议(protocol) AnyObject,因此您不能在其上使用 for 循环。如果你想这样做,你必须做类似下面的事情:

for item in directoryContent as [AnyObject] {
//Do stuff
}

关于xcode - 类型 'AnyObject' 不符合协议(protocol) 'SequenceType',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25563655/

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