gpt4 book ai didi

ios - NSPredicate predicateWithFormat 导致异常

转载 作者:行者123 更新时间:2023-11-29 11:16:15 25 4
gpt4 key购买 nike

任何人都可以帮助我使用下面的代码。它在我看来是正确的,但最后一条语句会导致异常。我想要做的就是创建一个 NSPredicate 以与 NSFetchRequest 一起使用。
根据调试器,下面的“Array”变量具有这四个对象:

Array   =   (__NSArrayI *)  0x6b930e0   4 objects
0 = (__NSCFConstantString *) 0x4067c String1
1 = (__NSCFConstantString *) 0x408ac String2
2 = (__NSCFConstantString *) 0x408bc String3
3 = (__NSCFConstantString *) 0x408cc String4


// Defines from header file
#define ATT_NODE_LEVEL @"nodeLevel"
#define NODE_LVL2 4

-(BOOL)initLVL2{
NSString *cond = [[NSString alloc] initWithFormat:@"parent.fullName"];

/* CAUSES AN EXCEPTION */
NSPredicate *pred = [NSPredicate predicateWithFormat:@"(%K == &@) && (%K == %@)", ATT_NODE_LEVEL, [NSNumber numberWithInt:NODE_LVL2], cond, [Array objectAtIndex:0]];
...
}

调试器输出:

objc[6076]: EXCEPTIONS: throwing 0x6e3ddf0 (object 0x6e3fb30, a NSException)
objc[6076]: EXCEPTIONS: searching through frame [ip=0xee0dc0 sp=0xbfffcfc0] for exception 0x6e3ddd0
objc[6076]: EXCEPTIONS: unwinding through frame [ip=0xee0dc0 sp=0xbfffcfc0] for exception 0x6e3ddd0
objc[6076]: EXCEPTIONS: handling exception 0x6e3ddd0 at 0xee0dc9
objc[6076]: EXCEPTIONS: rethrowing current exception
objc[6076]: EXCEPTIONS: searching through frame [ip=0xee0ddf sp=0xbfffcfc0] for exception 0x6e3ddd0
objc[6076]: EXCEPTIONS: searching through frame [ip=0xee0bde sp=0xbfffd000] for exception 0x6e3ddd0
objc[6076]: EXCEPTIONS: unwinding through frame [ip=0xee0ddf sp=0xbfffcfc0] for exception 0x6e3ddd0
objc[6076]: EXCEPTIONS: finishing handler
objc[6076]: EXCEPTIONS: unwinding through frame [ip=0xee0df3 sp=0xbfffcfc0] for exception 0x6e3ddd0
objc[6076]: EXCEPTIONS: unwinding through frame [ip=0xee0bde sp=0xbfffd000] for exception 0x6e3ddd0
objc[6076]: EXCEPTIONS: handling exception 0x6e3ddd0 at 0xee0c29
objc[6076]: EXCEPTIONS: rethrowing current exception
objc[6076]: EXCEPTIONS: searching through frame [ip=0xee0c16 sp=0xbfffd000] for exception 0x6e3ddd0
objc[6076]: EXCEPTIONS: searching through frame [ip=0x1496db3 sp=0xbfffea00] for exception 0x6e3ddd0
objc[6076]: EXCEPTIONS: unwinding through frame [ip=0xee0c16 sp=0xbfffd000] for exception 0x6e3ddd0
objc[6076]: EXCEPTIONS: finishing handler
objc[6076]: EXCEPTIONS: unwinding through frame [ip=0xee0c40 sp=0xbfffd000] for exception 0x6e3ddd0
objc[6076]: EXCEPTIONS: unwinding through frame [ip=0x1496db3 sp=0xbfffea00] for exception 0x6e3ddd0
objc[6076]: EXCEPTIONS: handling exception 0x6e3ddd0 at 0x1496e46
objc[6076]: EXCEPTIONS: rethrowing current exception
objc[6076]: EXCEPTIONS: searching through frame [ip=0x1496e0f sp=0xbfffea00] for exception 0x6e3ddd0
objc[6076]: EXCEPTIONS: unwinding through frame [ip=0x1496e0f sp=0xbfffea00] for exception 0x6e3ddd0
objc[6076]: EXCEPTIONS: finishing handler
objc[6076]: EXCEPTIONS: unwinding through frame [ip=0x1496e38 sp=0xbfffea00] for exception 0x6e3ddd0

最佳答案

您的谓词格式字符串有一个 NSNumber 的 &@ 标记。将其更改为 %@。

关于ios - NSPredicate predicateWithFormat 导致异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9307677/

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