【发布时间】:2017-10-21 22:02:17
【问题描述】:
我是 Swift 的新手。在下面的代码中,它检索照片并将它们放入一个数组中。现在我想在图像视图中显示它们。我该怎么做?
我的意思是,例如,如何在图像视图中显示数组的元素。
var list :[PHAsset] = []
PHPhotoLibrary.requestAuthorization { (status) in
switch status
{
case .authorized:
print("Good to proceed")
let fetchOptions = PHFetchOptions()
let allPhotos = PHAsset.fetchAssets(with: .image, options: fetchOptions)
print(allPhotos.count)
allPhotos.enumerateObjects({ (object, count, stop) in
list.append(object)
})
print("Found \(allPhotos.count) images")
case .denied, .restricted:
print("Not allowed")
case .notDetermined:
print("Not determined yet")
}
另一个问题是:当我调用这个函数时,它似乎是异步执行的。我的意思是调用函数后的代码行将提前执行。这是因为 requestAuthorization 吗?
【问题讨论】: