[英]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 !
任何帮助将不胜感激!
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. 您正在为每个对象使用
[NSObject description]
方法,该方法将返回一个字符串,无论该字符串在此上下文中使用时是否有用。 Sometimes it's not useful at all. 有时它根本没有用。
To fix this issue implement description
in the MPCheckedCurrency
object: 要解决此问题,请在
MPCheckedCurrency
对象中实现description
:
- (NSString *)description
{
return [NSString stringWithFormat:@"[currenyCode=%@, currencyValue=%@]", currencyCode, currencyValue];
}
(you might also need to implement description
in the currencyCode
and currentValue
objects too. (您可能还需要在
currencyCode
和currentValue
对象中实现description
。
When you are using NSLog, it calls description method. 使用NSLog时,它将调用描述方法。
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];
}
@Adina - Your problem is that you are printing the complete object (the array) on NSLog. @Adina-您的问题是您要在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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.