Adina Marin
Adina Marin

Reputation: 663

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 !

Upvotes: 4

Views: 81

Answers (3)

vichevstefan
vichevstefan

Reputation: 898

When you are using NSLog, it calls description method.

So not the exact code but you need to do something like below;

@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;
}

-(NSString*)description{
     return [NSString stringWithFormat:@"code: %d, value : %f",currencyCode,currencyValue];
}

Upvotes: 1

Priyank
Priyank

Reputation: 269

@Adina - Your problem is that you are printing the complete object (the array) on NSLog. Instead you need to loop in the array and print actual object values something like this:

for(objmpcheckcurrency in oldsavedarray)
{
       NSLog(@"The content of oldSavedArray is %@ %@",objmpcheckcurrency.currencyCode, objmpcheckcurrency.currencyValue);
}

Upvotes: -1

trojanfoe
trojanfoe

Reputation: 122458

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.

Upvotes: 1

Related Questions