NSMutableArray Not showing actual values when NSLog in iphone application

后端 未结 2 676
旧时难觅i
旧时难觅i 2021-01-28 19:02

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(!         


        
相关标签:
2条回答
  • 2021-01-28 19:52

    You need to do something like this:

    NSArray *theArray = [[NSArray alloc] initWith...];
    NSLog(@"array contents: %@", theArray);
    
    0 讨论(0)
  • 2021-01-28 20:05

    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.
    }
    
    0 讨论(0)
提交回复
热议问题