3
我盡力了,但是我被卡在了這裏。我想從iPhone相機相冊導入所有照片。所以我想出了這個ALAssestsLibrary API。如何枚舉Swift中的ALAssetsGroup
photoLibrary.enumerateGroupsWithTypes(ALAssetsGroupType(ALAssetsGroupSavedPhotos), usingBlock: { group in
if group != nil
{
}
}, failureBlock: { error in println("\(error)")})
如何添加這行代碼。
group enumerateAssetsUsingBlock:groupEnumerAtion
我試着添加這個,但它沒有顯示任何enumerateAssetsUsingBlock屬性。
這是實際的代碼。 !在Objective-C
dispatch_async(dispatch_get_main_queue(),^
{
@autoreleasepool
{
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"error occour =%@", [myerror localizedDescription]);
};
ALAssetsGroupEnumerationResultsBlock groupEnumerAtion = ^(ALAsset *result, NSUInteger index, BOOL *stop)
{
if (result!=NULL)
{
if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto])
{
[self.g_imageArray addObject:result];
}
}
};
ALAssetsLibraryGroupsEnumerationResultsBlock
libraryGroupsEnumeration = ^(ALAssetsGroup* group, BOOL* stop)
{
if (group == nil)
{
return;
}
if (group!=nil) {
[group enumerateAssetsUsingBlock:groupEnumerAtion];
}
[self updatephotoList];
};
self.library = [[ALAssetsLibrary alloc] init];
[self.library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:libraryGroupsEnumeration
failureBlock:failureblock];
}
});
謝謝!不得不將UnsafePointer更改爲UnsafeMutablePointer雖然 – garafajon
@garafajon:您完全正確,這在Swift版本之間發生了變化。我已經更新了答案。感謝您的反饋! –