2015-05-04 16 views
4

我需要一些關於可能導致我的問題的原因。我有一個源代碼,我想對它進行一些調試,但我看不到變量。調試問題 - 值被隱藏

例如:

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

,我得到這樣的:

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>" 
) 

或本:

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

我得到某事像這樣:

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

可能是從這個問題:

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

我怎樣才能看到陣列的內容? 任何幫助將是apreciate!

+0

在'NSLog'之後放置一個斷點,然後可以查看數組中的內容。 –

+1

你的數組包含MPCheckedCurrency對象 –

+0

好的,我該怎麼做才能看到值? –

回答

1

對這些對象中的每一個都使用了[NSObject description]方法,該方法返回一個任何感覺在此上下文中使用時可能有用的字符串。有時它根本沒用。

要解決此問題在MPCheckedCurrency對象實現description:當您使用的NSLog

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

(你可能還需要實現在currencyCodecurrentValue對象description

+0

與xcode調試器的問題是一樣的 –

+0

@AdinaMarin我編輯了我的答案。 – trojanfoe

1

,它調用描述方法

所以不是確切的代碼,但你需要做下面的事情;

@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 - 你的問題是你正在NSLog上打印整個對象(數組)。相反,你需要在數組中循環並打印實際的對象值,如下所示:

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