开发者

NSStringFromClass can return nil when the arg isn't nil?

I'm getting some weird behavior in my CoreData wrapper class. Here's the function:

-(SystemCode*) getSystemCodeWithDescription:(NSString*)description andType:(Class)type {
    NSString* entityName = [NSStr开发者_运维问答ing stringWithFormat:@"%@", type]; 
    // NSStringFromClass(type); was my first try, it also returned a nil string
    SystemCode* result = [self getUniqueEntity:entityName predicate:@"Description == '%@'" predicateArg:description generateNew:NO];
    return result;
}

If I put a breakpoint on the 2nd line (SystemCode* result = ...) and run GDB I get the following output:

(gdb) print-object entityName
Unable to access variable "entityName"
Can't print the description of a NIL object.
(gdb) print-object type
Result

How can 'type' be a valid object, but when I try to convert it to a string, it just turns in to a nil string? My project is using the XCode 4.0 and running in the iPad 4.3 simulator if that matters.


Are you sure type is a Class?

Also, you can use po instead of print-object.


I figured out the issue. The class was working correctly, someone checked in a build target for debug that was optimized. It was just that gdb couldn't see the values. My bug was actually in the predicate, that's why no entities were being selected.


Try using class_getName from <objc/runtime.h>.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜