Creating NSPredicate dynamically by setting the key programmatically

后端 未结 2 1279
不知归路
不知归路 2021-02-06 05:28

Why does the former of following snippets work while not the latter ?

Snippet 1

NSPredicate *predicate = [NSPredicate predicateWithForma         


        
2条回答
  •  猫巷女王i
    2021-02-06 05:56

    coin_unique is a key, so it needs the %K format specifier:

    NSString *predicateText = @"coin_unique";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(%K == %@)", predicateText, [NSNumber numberWithInt:species]];
    

    The format syntax is described quite well here.

提交回复
热议问题