NSMutableArray Not showing actual values when NSLog in iphone application

会有一股神秘感。 提交于 2019-12-04 05:50:47

问题


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

回答1:


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. 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. 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.
}



回答2:


You need to do something like this:

NSArray *theArray = [[NSArray alloc] initWith...];
NSLog(@"array contents: %@", theArray);


来源:https://stackoverflow.com/questions/11732871/nsmutablearray-not-showing-actual-values-when-nslog-in-iphone-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!