Old ASS Log vs new ASOC log

Hi,

I have some difficult to understand the new mode that xCode use when log data (compared to old ASS).
PS: I’m new to Xcode 4.x and all his changes…
In particular seems there is no visual differences between list and records.
Following the Shane book at page 30 if you log the variable tempList you get in Xcode 4.1 the following (in the Target output window):

2011-08-08 14:21:49.970 tabella[2021:707] (
{
paperino = 0;
pippo = Applications;
pluto = aaa;
},
{
paperino = 0;
pippo = Desktop;
pluto = aaa;
},
{
paperino = 0;
pippo = Documents;
pluto = aaa;
},
{
paperino = 0;
pippo = Downloads;
pluto = aaa;
},
{
paperino = 0;
pippo = Library;
pluto = aaa;
},
{
paperino = 0;
pippo = Movies;
pluto = aaa;
},
{
paperino = 0;
pippo = Music;
pluto = aaa;
},
{
paperino = 0;
pippo = Pictures;
pluto = aaa;
},
{
paperino = 0;
pippo = Public;
pluto = aaa;
},
{
paperino = 0;
pippo = “apu_tmp”;
pluto = aaa;
}
)

The field pluto has fixed string with value aaa but from the log it seems not a string.
Same concept for field pippo where all values except api_tmp are not inside double quotes. Why?

The same result when you log the display selection (as in Shane book example to page 27)
The only string between double quotes is the name of custom folder created on my Home directory.
And another strange behavior is that even is the selection from array controller is coerced as list the log is written like “as record”.

(
{
paperino = 0;
pippo = “apu_tmp”;
pluto = aaa;
}
)

All this is normal or I need to know something else?

Stefano

This is normal. If the string is in one word, it does not present it between " ". Don’t know why, but I can assure you that it is a string. If it is an Cocoa object, you could test it with the className method of NSObject. And I think there was something similar in ASS… the class command from System Events maybe? Not sure…

I, for one, prefer the new layout especially when it is arrays, the layout is much cleaner. :slight_smile:

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

OK for sting (one word or two words separated by spaces).

But what about is you log the display selection (as in Shane book example to page 27)
The strange behavior is that even is the selection from array controller is coerced as list the log is written like “as record”.

(
{
paperino = 0;
pippo = “apu_tmp”;
pluto = aaa;
}
)

Stefano

Also normal. If you ask an NSArrayController to return the currently selected object it always returns an NSArray. You then need to ask it’s objectAtIndex_(0)'s valueAtKey_(“nameOfYourKey”) to get it’s contents. Or use a repeat loop if you expect more than one item to be selected in your array.

Does that answer your question?

Browser: Safari 6533.18.5
Operating System: Mac OS X (10.6)

the %@ token of NSLog calls the description method of the target object.
The description method of NSArray and NSDictionary displays the contents in parentheses respective braces
and escapes automatically non-alphanumeric strings. This affects only the appearance of the log lines.

In your example NSLog displays an array () containing one dictionary object {}

Hi, Thanks for all reply.

What I expect is to have in the log a list because the displaySelection command (see page 27 of Shane book) say:

Tell theArrayController to set theSel to selectedObjects() as list

In previous ASS when I log a list it appear as list not as records with labels before value.

Or I miss something?

Stefano

It does appear as list. In Cocoa lists (arrays) are represented by parentheses and key/value objects by braces

Stefano,

I think the point you are missing, is that this is not a simple list that just has values in it, it is a list of records. The fact that the log has “(” at the top and “)” at the bottom means that it is a list (or an NSArray), but in this case, each item in the list is a record.

Ric

Hi community,

OK I understand now. So this means that data from theArrayController are returned every time as list of records?
In previous ASS there was (if I remember good) the possibility to return data as list or data as records.

Stefano

No, I don’t think that is right (but I’m still using Xcode 3.2). Try doing this and see what it logs:

on applicationWillFinishLaunching_(aNotification)
		set simpleArray to current application's NSArray's arrayWithArray_({"One", "two", "three"})
		set recordArray to current application's NSArray's arrayWithArray_({{aName:"Robert", age:20}, {aName:"Barack", age:50}, {aName:"Hilary", age:63}})
		log simpleArray
		log recordArray
	end applicationWillFinishLaunching_

In Xcode 3.2, the log looks like this:

If the array is a “simple” one it logs as a list, if it is an array of dictionaries (or records), it logs as a list of records. It doesn’t matter if I put “as list” in the log statements, it still logs the same thing. How does it behave in Xcode 4? The array you are working with from Shane’s book is an array of dictionaries, so that’s how it logs.

Ric

Yes, that’s pretty much it. But an NSArray can contain objects of various nature, like NSDate, NSInteger or even other NSArray or NSDictionary. This is when you need to coerce them to AS world with “as string”, “as integer”, “as list”, etc. Unless you intend to apply other Cocoa methods to them. I for one try to keep things in Cocoa as much as possible, for the multiple methods available and the speed too. Using an NSPredicate on an NSArray is much faster than doing a repeat loop to find what you want. :slight_smile:

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)