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
}
}
}
the compile error is below:
Type 'AnyObject' does not conform to protocol 'SequenceType'
what does this menas?
who can help me ,thks a lot!!!!
Apple states in The Swift Programming Language:
Right now,
directoryContent
is just conforming to protocolAnyObject
, so you can't use for loops over it. If you want to do so, you have to do something similar to the following:contentsOfDirectoryAtPath
returns anNSArray
, whereas you are casting it toAnyObject
. The solution is to cast it to either[AnyObject]?
orNSArray
:or
Then use an optional binding before the for loop:
Looking at the
contentsOfDirectoryAtPath
documentation, it states it always returns an array - so what said above can be reduced to unwrapping the return value to either a swift or objc array, with no need to use the optional binding:or