开发者

Trying to make the code readable

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜