News for hackers. Stuff that matters.
Re:In defence of Objective-C by hboon on Monday October 17, 2011 @01:58AM (#3119339)
Can't get rid of the issue completely, but at least we can have:

#define MD(val, key, vals...) [NSMutableDictionary dictionaryWithObjectsAndKeys:val, key, ## vals , nil]

then do:

NSMutableDictionary* dict = MD(@"value1", @"key1", @"value2", @"key2")

And so on. Courtesy of http://news.ycombinator.com/item?id=1789839.

Re:In defence of Objective-C by stephth on Monday October 17, 2011 @06:00AM (#3119857)
That ## vals syntax is new to me. What's the difference with the following?

  #define MD(...) [NSMutableDictionary dictionaryWithObjectsAndKeys:__VA_ARGS__, nil]
Re:In defence of Objective-C by hboon on Monday October 17, 2011 @06:27AM (#3119928)
Both of them wouldn't work for MD() due to the trailing nil.

But for MD(val, key, vals...), it'd give you a slightly better error, complaining about the number of arguments when you do MD().

Otherwise they are the same in this case.

## removes one non-whitespace character – often the comma – before the ## if vals or __VA_ARGS__ is empty.

e.g

  #define MO_LogDebug(fmt, ...) NSLog((@"DEBUG " fmt), ##__VA_ARGS__)

  MO_LogDebug(@"This works as expected %d", resultCode);

  // Removes the comma automatically in here:
  // NSLog((@"DEBUG " @"This works too without args"), );
  MO_LogDebug(@"This works too without args");
Re:In defence of Objective-C by 5hoom on Monday October 17, 2011 @04:57AM (#3119726)
Very nice, thanks for that.