使用类型表达式初始化“void(^)(struct ALAssetsGroup *, BOOL *)”时不兼容的块指针类型
我看到 SO 上有几个人已经成功地使用了这段代码。但我收到了不兼容的块指针错误:
不兼容的块指针类型
void(^)(struct ALAssetsGroup *, BOOL *)
用类型的表达式
void(^)(ALAsset *, NSUInteger, BOOL *)
初始化有任何提示吗? (使用完整代码进行编辑)
ALAssetsLibrary *library =[[ALAssetsLibrary alloc]init];
void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop){
if(result != NULL) {
NSLog(@"See Asset: %@", result);
}
};
void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {NSLog(@"dont See Asset: ");
[group enumerateAssetsUsingBlock:assetEnumerator];
}
};
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum
usingBlock:assetGroupEnumerator
failureBlock: ^(NSError *error) {
NSLog(@"Failure");
}];
I saw several people on SO have been using this code successfully. But I got the incompatible block pointer error:
Incompatible block pointer types initializing
void(^)(struct ALAssetsGroup *, BOOL *)
with an expression of type
void(^)(ALAsset *, NSUInteger, BOOL *)
Any hints? (EDIT with complete code)
ALAssetsLibrary *library =[[ALAssetsLibrary alloc]init];
void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop){
if(result != NULL) {
NSLog(@"See Asset: %@", result);
}
};
void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {NSLog(@"dont See Asset: ");
[group enumerateAssetsUsingBlock:assetEnumerator];
}
};
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum
usingBlock:assetGroupEnumerator
failureBlock: ^(NSError *error) {
NSLog(@"Failure");
}];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,区块新手...但我在这里找到了资产组枚举器块的另一个示例,并且它的声明中没有
struct
。我尝试从上面的代码中删除它,它仍然工作正常并且没有错误消息。希望更了解struct
的人可以解释一下吗?尝试将这一行更改
为:
我认为底线是
ALAssetsLibrary enumerateGroupsWithTypes: usingBlock:
期望一个看起来像(ALAssetsGroup *, BOOL *)
的块,而不是(struct ALAssetsGroup *, BOOL *)
。OK, newbie at blocks... but I found another example of an asset group enumerator block on here, and it didn't have
struct
in the declaration. I tried removing it from the code above, and it still works fine and doesn't have the error message. Hopefully someone who understandsstruct
better can explain?try changing this line:
to this:
I think the bottom line is that the
ALAssetsLibrary enumerateGroupsWithTypes: usingBlock:
expects a block looking like(ALAssetsGroup *, BOOL *)
not(struct ALAssetsGroup *, BOOL *)
.预期类型和实际类型之间的区别仅在于工作struct,即
struct ALAsset*
与ALAsset*
。 (在您的文字描述中,ALAsset
和ALAssetGroups
之间看起来不匹配,但我认为您在复制错误消息时犯了一个错误。)我不太明白在哪里这些差异来自(可能是由于在某处使用了 C++?)。
无论如何,最好的解决方案是分别使用类型定义
ALAssetsGroupEnumerationResultsBlock
或ALAssetsLibraryGroupsEnumerationResultsBlock
,例如:The difference between the expected and the actual type is just the work struct, i.e.
struct ALAsset*
vs.ALAsset*
. (In your textual description it looks like a mismatch betweenALAsset
andALAssetGroups
, but I think you made a mistake in copying the error message.)I don't quite understand where these differences come from (possibly due to the use of C++ somewhere?).
Anyway, the best solution is to use the type definition
ALAssetsGroupEnumerationResultsBlock
orALAssetsLibraryGroupsEnumerationResultsBlock
respectively, e.g.: