I am trying to create a define like this
#define ICONS [NSArray arrayWithObjects: [NSNumber numberWithFloat:33.0f], [NSNumber numberWithFloat:93.0f], [NSNumber numberWithFloat:149.0f], [NSNumber numberWithFloat:205.0f], [NSNumber numberWithFloat:314.0f], [NSNumber numberWithFloat:370.0f], [NSNumber numberWithFloat:426.0f], [NSNumber numberWithFloat:482.0f], nil]
but, I would like to write it organized in lines - to make the code readable, like
#define ICONS [NSArray arrayWithObjects:
[NSNumber numberWithFloat:33.0f],
[NSNumber numberWithFloat:93.0f],
[NSNumber numberWithFloat:149.0f],
[NSNumber numberWithFloat:205.0f],
[NSNumber numberWithFloat:314.0f],
[NSNumber numberWithFloat:370.0f],
[NSNumber numberWithFloat:426.0f],
[NSNumbe开发者_StackOverflow社区r numberWithFloat:482.0f],
nil]
but when I break the define in lines, Xcode yells like mad.
Is there a way to break the line and organize the code as I want?
To split a #define across lines you need to append \
to the lines.
#define ICONS [NSArray arrayWithObjects: \
[NSNumber numberWithFloat:33.0f], \
[NSNumber numberWithFloat:93.0f], \
[NSNumber numberWithFloat:149.0f], \
[NSNumber numberWithFloat:205.0f], \
[NSNumber numberWithFloat:314.0f], \
[NSNumber numberWithFloat:370.0f], \
[NSNumber numberWithFloat:426.0f], \
[NSNumber numberWithFloat:482.0f], \
nil]
Per the C spec, multiline defines need a '\' at the end of each line:
#define ICONS [NSArray arrayWithObjects: \
[NSNumber numberWithFloat:33.0f], \
[NSNumber numberWithFloat:93.0f], \
[NSNumber numberWithFloat:149.0f], \
[NSNumber numberWithFloat:205.0f], \
[NSNumber numberWithFloat:314.0f], \
[NSNumber numberWithFloat:370.0f], \
[NSNumber numberWithFloat:426.0f], \
[NSNumber numberWithFloat:482.0f], \
nil]
精彩评论