Viewing the arrays



While trying to get my head around this chapter I wanted to see what was in the array, Employees. I used


to print the array. That printed this

2012-09-18 13:17:35.942 BMITime[71423:303] (
"<Employee 0: $0 in assets to date>",
"<Employee 1: $0 in assets to date>",
"<Employee 2: $0 in assets to date>",
"<Employee 3: $0 in assets to date>",
"<Employee 4: $0 in assets to date>",
"<Employee 5: $0 in assets to date>",
"<Employee 6: $0 in assets to date>",
"<Employee 7: $0 in assets to date>",
"<Employee 8: $0 in assets to date>",
"<Employee 9: $0 in assets to date>"

I thought the array would have the weight and height of the person in it as well. What am I missing?

Best wishes



They will be printed only if there is a description method that prints them, and that description method must be called somehow. If you print the contents of an array with %@, the array will call the description method of each item in it.


Thanks for the information. I am surprised you can’t see what is in the the array in xcode. Do you have to write your own code to see what is in the array?

Best wishes



Oh, but you can see what’s in the array. When you log an array, it sends the -description message to every object it contains. It’s then that object’s responsibility to log its own attributes.

That is to say, a person’s weight isn’t in the array itself. It’s an attribute of a person. There are lots of person objects in the array.

Another example: If I have an array of ten satchels, the array only knows about the satchel objects themselves, not what’s in them. Only the satchels themselves know their individual contents. So if I want to log out everything in each of my satchels, each satchel needs to be able to report its contents - so I’d implement a -description in my Satchel class.