2012-02-16 5 views
1

Quelqu'un peut-il m'aider avec mon code ci-dessous. Cela me semble juste, mais la dernière déclaration provoque une exception. Tout ce que j'essaie de faire est de créer un NSPredicate à utiliser avec un NSFetchRequest.
Le "Array" variable a en dessous de ces quatre objets selon le débogueur:NSPredicate predicateWithFormat provoque l'exception

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]]; 
... 
} 

sortie Debugger:

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 

Répondre

2

Votre chaîne de format prédicat a un & @ jeton pour un NSNumber. Changez-le en% @.

+1

Cela '&' était mon problème. Merci beaucoup bneely – Vince613