576NSDictionary and NSArray plist examples

NSDictionary




	arrayKey
	
		string1
		string2
		string3
		string4
	
	dicKey
	
		key1
		object1
		key2
		object2
		key3
		object3
	
	key2
	object2
	key3
	object3



NSArray




	string1
	string2
	string3
	
		key1
		object1
		key2
		object2
		key3
		object3
	
	string5




At the end, after </plist>, there’s another CR.

220Linking libxml2 in Xcode

How to link libxml2 in Xcode for use with TouchXML? 1. Copy TouchXML files. They are wrappers to libxml2. 2. Instead of copying an extra copy of libxml2 to the project frameworks, add the following to the target information: Header Search Paths:
/usr/include/libxml2
Other Linker Flags:
-lxml2
(Of course assuming, that libxml2 is present at this location on your system.) In the Target Info, make sure to select the current configuration to see the values. Otherwise you get <Multiple Values> and they look like it’s not possible to edit them. Took me a while to figure out, that changing the configuration [top left] was the key. Duh.

214NSMutableArray: setObject vs. setValue

Following situation Using TouchXML to parse XML data, works without problem on example XML files, but crahes on mine. Problem Empty values in my data set. (sometimes <place>somePlace</place>, sometimes <place></place>)
/* CXMLDocument setup & parsing omitted */
NSString *e = [[resultElement childAtIndex:counter] stringValue];
NSString *k = [[resultElement childAtIndex:counter] name];


[blogItem setObject:e forKey:k];
// crashes when e is empty. Displays a (null), is nil
Solution 1 Check for empty e, replace nil with empty string
// check if element is empty
if ( nil == e ) {	// ...or the less elegant (0 == [e length])
	e = @"";
}
[blogItem setObject:e forKey:k];
Solution 2 Use setValue instead of setObject, as setObject crashes and burns when it encounters nil, whereas setValue specifically deals only with strings and handles nil gracefully.
[blogItem setValue:e forKey:k];

206NSXMLParser vs libxml2

NSXMLParser parses XML, reports when each node ends, better for very, very large documents. libxml2 loads whole xml file into memory. http://code.google.com/p/touchcode/wiki/TouchXML http://code.google.com/p/kissxml/ iPhone SDK Development by Bill Dudney and Chris Adamson NSXMLParser initWithContentsOfURL: may block GUI while downloading, can not handle HTTP authentication. initWithData: accumulate data with NSURLConnection’s delegate -didReceiveResponse, -didReceiveData, -connectionDidFinishLoading. TouchXML – copy TouchXML files to project – in “Targets”, select target > Get Info > add /usr/include/libxml2 to Header Search Paths – add libxml2.dylib to “Frameworks” UPDATE instead of adding libxml2.dylib link to the Framework on the system: Other Linker Flags:
-lxml2
Linking libxml2 in Xcode