gpt4 book ai didi

cocoa - NSPredicate 在 QuickLook 插件中引发 'Unknown number type or nil passed to arithmetic function expression.'

转载 作者:行者123 更新时间:2023-12-03 17:42:19 24 4
gpt4 key购买 nike

我有一个 NSDictionary 的 NSArray。所有字典都有一个关键的image-path
我想获取一个仅包含与键 image-path 的给定值(我的 path 变量的内容)匹配的字典的过滤数组。

我使用这一行验证了数据的结构(它打印了关键图像路径的字典的所有值):

NSLog(@"array key paths: %@", [mountedImages valueForKeyPath:@"image-path"]);

我正在使用此代码:

NSString *path = @"value-I-want-to-match";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(image-path LIKE[cd] \"%@\")", path];
NSArray *filteredArray = nil;
filteredArray = [mountedImages filteredArrayUsingPredicate:predicate];

最后一行崩溃并产生以下错误:

[ERROR] Computing 6571367.19831142 raised 'Unknown number type or nil passed to arithmetic function expression.'

我在 QuickLook 插件中执行此操作。我可以使用 gdb 逐步执行我的代码,但我似乎没有得到任何跟踪。我只得到:

[...]
[ERROR] Computing 6571367.19831142 raised 'Unknown number type or nil passed to arithmetic function expression.'
[Switching to process 23335 thread 0x8903]
[Switching to process 23335 thread 0xa703]
[Switching to process 23335 thread 0x8903]
Program ended with exit code: 0

最佳答案

您应该删除放置在谓词格式字符串中的转义引号。如 Apple 谓词格式字符串引用中所述:

When string variables are substituted into a format string using %@ , they are surrounded by quotation marks. If you want to specify a dynamic property name, use %K in the format string, as shown in the following example.

 NSString *attributeName = @"firstName";
NSString *attributeValue = @"Adam";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like %@", attributeName, attributeValue];

The predicate format string in this case evaluates to firstName like "Adam".

Single or double quoting variables (or substitution variable strings) cause %@, %K, or $variable to be interpreted as a literal in the format string and so prevent any substitution. In the following example, the predicate format string evaluates to firstName like "%@" (note the single quotes around %@).

 NSString *attributeName = @"firstName";
NSString *attributeValue = @"Adam";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like '%@'", attributeName, attributeValue];

在您的情况下,您的谓词被创建为 image-path LIKE[cd] "%@",在用于过滤数组时无法正确评估。

关于cocoa - NSPredicate 在 QuickLook 插件中引发 'Unknown number type or nil passed to arithmetic function expression.',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9130993/

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