Mortoc
Mortoc

Reputation: 610

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 = [NSString 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.

Upvotes: 0

Views: 1495

Answers (3)

Mortoc
Mortoc

Reputation: 610

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.

Upvotes: 1

bbum
bbum

Reputation: 162712

Are you sure type is a Class?

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

Upvotes: 1

John Calsbeek
John Calsbeek

Reputation: 36497

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

Upvotes: 0

Related Questions