Debugging problems - values ​​are hidden

I need some idea of ​​what might be causing my problem. I have the source code and I want to do debugging on it, but I do not see the variables.

For instance:

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

and I get the following:

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 the following:

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

There may be a problem:

@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 contents of arrays? Any help would be helpful!

+4
source share
3 answers

You use a method [NSObject description]for each of these objects that returns a string of what, in his opinion, might be useful when used in this context. Sometimes this is not useful at all.

To fix this problem, run descriptionin the object MPCheckedCurrency:

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

( description currencyCode currentValue.

+1

NSLog, .

, - ;

@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];
}
+1

@Adina - Your problem is that you are printing the complete object (array) to NSLog. Instead, you need to loop into the array and print the actual values ​​of the objects like this:

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

All Articles