gpt4 book ai didi

objective-c - 带子数组的 NSPredicate

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:27:03 25 4
gpt4 key购买 nike

我正在查看以下类型的数据结构:

{    author = "Author 1";    channelIds =         (        7    );},{    author = "Author 2";    channelIds =         (        7,        1    );},,{    author = "Author 3";    channelIds =         (        3,        7    );}

I'd like to build an array consisting of all items where channeldIds = 7.

I was trying things along the lines of the following predicate:

NSPredicate * filterById = [NSPredicate predicateWithFormat:@"channelIds[0] = '7'"];
  • 我怎样才能在这里做我想做的事?
  • 我可以有 x 个 channelId,有什么方法可以在谓词中迭代吗?

蒂亚,S.

最佳答案

更简单:

NSPredicate *filterById = [NSPredicate predicateWithFormat:@"channelIds CONTAINS %@", @"7"];

这是假设您的 channelIds 值是一个 strings 数组。如果它是一个数字数组 (NSNumber),那么您的格式字符串将只是 @"channelIds CONTAINS 7"

关于objective-c - 带子数组的 NSPredicate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4997720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com