我有一个nsmutablearray,里面有“gameobject”类型的对象。gameobject有很多属性,其中一个是“gameobjecttype”。gameobjecttype“是gameobjecttypeenum类型。我希望能够过滤这个nsmutablearray,以便只返回特定类型的gameobjects。我已经准备好了以下内容,但它给了我一个“错误访问”错误:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"gameObjectType = %@", gameObjectType];
return [gameObjects filteredArrayUsingPredicate:predicate];

是否可以将“自定义”类型(即我定义的这个枚举)传递到谓词WithFormat调用中?

最佳答案

字符串格式说明符%@表示传递整数值时的对象。您可能需要将gameobjecttype类型转换为int并使用%d说明符。查看string format specifiers了解更多信息。

关于objective-c - 根据枚举属性过滤NSMutableArray,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3033528/

10-09 16:15