Codec ░ NSMutableArray

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];

289Simulating Keyboard & Mouse Events. And Key-Modifier Events 275UIWebView – checking when user clicks a link 269Caching on Objective-C with NSURLCache 265Like explode(), only componentsSeparatedByString: 259The mystery of self.* – resolved?