NSarray

Discussion in 'Mac Programming' started by BollywooD, Dec 28, 2009.

  1. BollywooD macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #1
    probably a simple question, but....
    I have an NSArray, which when i check it contents:

    Code:
    NSLog(@"myArray: %@", myArray);

    it looks like this:
    Code:
     myArray: (
        "<Info: 0x118a9c740>",
        "<Info: 0x1192f8880>"
    )
    how can I see what is contained in the Array?

    thanks in advance:confused:
     
  2. robj macrumors regular

    Joined:
    Dec 23, 2009
    Location:
    Madrid, Spain
    #2
    You can override the description method of the objects of you array.
     
  3. BollywooD thread starter macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
  4. robj macrumors regular

    Joined:
    Dec 23, 2009
    Location:
    Madrid, Spain
    #4
    Simply add to your class a method called description:
    Code:
    -(NSString *) description {
       return @"whatever you want";
    }
    And NSLog would call it to print the info
     
  5. BollywooD thread starter macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #5
    I hate to say it but im still lost....

    Ive been looking at code ALL day
     
  6. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    Every Cocoa object has a built-in description method that returns a string describing that object. By default Cocoa provides a basic description, but you can override that method to return something that is clearer. When you NSLog an array, it spits out the result of this method for every object in the array. So in your Info class, you would override the method and possibly return a combination of the important ivars in that class (using for example NSString's stringWithFormat to generate the string).
     

Share This Page