问题描述
我正在做一个数组的NSLog,但是它没有显示以下值,而不是数据.我不知道如何解决此问题并从数组中获取值
I am doing an NSLog of an array but instead of data it shows the following values. I do not know how to fix this issue and get the values from the array
if(!surveyQuestions){
surveyQuestions=[[NSMutableArray alloc]init];
}
Total Survey Questions 3
2012-07-31 08:54:53.555 SQL[442:9203] SurveyQuestions (
"<QuestionData: 0x4da10f0>",
"<QuestionData: 0x4b9f120>",
"<QuestionData: 0x4ba42e0>"
)
推荐答案
我不确定您要做什么,但是:可以肯定的是,糟糕的数组对象不知道您自己的自定义类的功能和方式,打印类实例的最好方法是调用它的description方法,这是您所看到的,实际上并没有什么帮助.您可能想做两件事:
I'm not sure what you're trying to do but: it's certain that the poor array object has no idea what and how your own custom class does, its best possibility to print an instance of your class is to call its description method, which you see, and which is not really helpful. You maybe want to do two things:
I.如果您只想打印这样的对象,请覆盖类的描述方法,并使用一些格式字符串(假设您没有编写一行代码,我不得不回想一下):
I. If you only want to print your objects like this, override the description method of your class and use some format string (given that you haven't written a single line of code I have to fall back to guess):
- (NSString *)description
{
return [NSString stringWithFormat:@"Name: %@, address: %@", self.name, self.address];
}
II.如果要在其他地方使用类的数据,则可能需要手动遍历其属性:
II. If you want to use the data of your class elsewhere, you probably want to loop through its properties manually:
for (QuestionData *d in surveyQuestions)
{
NSLog(@"%@", d.name);
// etc.
}
这篇关于NSMutableArray在iPhone应用程序中显示NSLog时不显示实际值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!