Я пытаюсь присвоить результаты в блоке переменной блока.Вот мой код:
__block UIImage *latestImage;
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:^(ALAssetsGroup *group, BOOL *stop){
// Within the group enumeration bl ock, filter to enumerate just photos.
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
// Chooses the photo at the last index
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:([group numberOfAssets]-1)]
options:0
usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop){
// the end of the enumeration is signaled by asset == nil.
if (alAsset){
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
latestImage = [UIImage imageWithCGImage:[representation fullResolutionImage]];
}
}];
}
failureBlock: ^(NSError *error){
// handle error
NSLog(@"No groups");
}
];
return latestImage;
Я подтвердил, что переменная latestImage была установлена внутри блока, отображая ее в UIImageView изнутри блока.Однако, когда я пытаюсь вернуть этот объект, как показано в коде выше, он ничего не возвращает.
Что мне не хватает?
Спасибо.