比较 switch 语句中的 ALAssetGroupType
您好,我正在调用 ALAssetsLibrary,
-enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:block failureBlock:failure;
然后在枚举块内我想比较返回的组的类型并将其添加到相关数组中。我尝试过
^( ALAssetsGroup *group, BOOL *stop )
{
NSLog(@"Group %@", group );
ALAssetGroupType assetType = (ALAssetGroupType)[group valueForProperty:ALAssetsGroupPropertyType];
NSLog( @"Asset type %@", assetType );
switch( assetType )
{
case ALAssetsGroupAplbum :
NSLog( @"Found ALBUM" );
[albums addObject:group];
break;
}
}
初始日志跟踪“Group ALAssetsGroup - 名称:照片库,类型:相册,资产数量:177”,
下一个日志是“资产类型 2”,
但第三个日志从未被调用。
有什么想法我做错了吗?
Hi I am calling ALAssetsLibrary's
-enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:block failureBlock:failure;
then inside the enumeration block i want to compare the type of group returned and add it to the relevant array. I have tried
^( ALAssetsGroup *group, BOOL *stop )
{
NSLog(@"Group %@", group );
ALAssetGroupType assetType = (ALAssetGroupType)[group valueForProperty:ALAssetsGroupPropertyType];
NSLog( @"Asset type %@", assetType );
switch( assetType )
{
case ALAssetsGroupAplbum :
NSLog( @"Found ALBUM" );
[albums addObject:group];
break;
}
}
The Initial log traces out "Group ALAssetsGroup - Name:Photo Library, Type:Album, Assets count:177"
The next log is "Asset type 2"
but the third log never get's called.
Any ideas what i am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
valueForProperty:
返回一个对象。对于ALAssetsGroupPropertyType
,它返回一个封装在 NSNumber 中的 ALAssetGroupType 常量。 (请参阅此处的文档。)因此,通过转换为 < code>ALAssetGroupType 您正在使用对象的内存地址作为开关值。您需要使用
intValue
获取 NSNumber 的基础整数值:valueForProperty:
returns an object. In the case ofALAssetsGroupPropertyType
it returns an ALAssetGroupType constant wrapped in an NSNumber. (See docs here.)So by casting to
ALAssetGroupType
you're using the object's memory address as your switch value. You need to get the underlying integer value of the NSNumber usingintValue
: