Search code examples
iosobjective-cdebuggingnscodernsarchiving

Debuging problems - Values are hidden


I need some ideea about what can be he cause of my problem . I have a source code and i want to make some debug on it , but i can't see the variables.

For example :

NSArray *oldSavedArray = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingSavedArray];
NSLog(@"The content of oldSavedArray is%@",oldSavedArray);

and i get this :

2015-05-04 11:06:28.275 MobilePocket[59803:12619613] The content of oldSavedArray is(
    "<MPCheckedCurrency: 0x7f9903b21090>",
    "<MPCheckedCurrency: 0x7f9903b20fc0>",
    "<MPCheckedCurrency: 0x7f9903b21130>",
    "<MPCheckedCurrency: 0x7f9903b21170>",
    "<MPCheckedCurrency: 0x7f9903b21510>",
    "<MPCheckedCurrency: 0x7f9903b21190>"
)

or for this :

 NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults];
    NSData *dataRepresentingSavedArray = [currentDefaults objectForKey:currencyCheckedArrayKey];

i get sth like this :

(lldb) po dataRepresentingSavedArray
<62706c69 73743030 d4010203 0405064d 4e582476 65727369 6f6e5824 6f626a65 63747359 24617263 68697665 72542474 ...etc

May be the problem from this :

@implementation MPCheckedCurrency

@synthesize currencyCode;
@synthesize currencyValue;

- (void)encodeWithCoder:(NSCoder *)coder;
{
    [coder encodeObject:currencyCode forKey:currencyCheckedCodeKey];
    [coder encodeObject:currencyValue forKey:currencyCheckedValueKey];
}

- (id)initWithCoder:(NSCoder *)coder;
{
    self = [super init];
    if (self != nil)
    {
        self.currencyCode = [coder decodeObjectForKey:currencyCheckedCodeKey];
        self.currencyValue = [coder decodeObjectForKey:currencyCheckedValueKey];
    }
    return self;
}

How can i see the content of arrays ? Any help will be apreciate !


Solution

  • You are using the [NSObject description] method for each of those objects, which returns a string of whatever it feels might be useful when used in this context. Sometimes it's not useful at all.

    To fix this issue implement description in the MPCheckedCurrency object:

    - (NSString *)description
    {
        return [NSString stringWithFormat:@"[currenyCode=%@, currencyValue=%@]", currencyCode, currencyValue];
    }
    

    (you might also need to implement description in the currencyCode and currentValue objects too.