爲了清理我的代碼,在代碼中使用#define
是不是很好?大多數例子是幾行,定義尺寸等。
在我的例子中,我爲下面的一段代碼有單獨的頭文件。以這種方式使用#define
是否是好習慣?使用#define,良好的做法?
#define KCHECKREFERENCE if([self.partClasses containsObject:@"Part1"]||[self.partClasses containsObject:@"Part2"]||[self.partClasses containsObject:@"Part3"]||[self.partClasses containsObject:@"Part4"]||[self.partClasses containsObject:@"Part5"]||[self.partClasses containsObject:@"Part6"]||[self.partClasses containsObject:@"ICDomesticEICPart7"]||[self.partClasses containsObject:@"ICDomesticEICPart8"]){\
[self.currentPartView save];\
self.previousPartView = self.currentPartView;\
int nextPartNumber = 1;\
ICCertificateComponent *part = [self loadPart:nextPartNumber];\
self.currentPartView = part;\
CGRect nextPartViewFrame = self.currentPartView.view.frame;\
nextPartViewFrame.origin.x = 320.0f;\
self.currentPartView.view.frame = nextPartViewFrame;\
CGRect previousPartViewFrame = self.previousPartView.view.frame;\
previousPartViewFrame.origin.x = -320.0f;\
nextPartViewFrame.origin.x = 0;\
[self.view insertSubview:self.currentPartView.view belowSubview:self.navBarView];\
NSTimeInterval duration = 0.1;\
[UIView animateWithDuration:duration\
animations:^{\
self.previousPartView.view.frame = previousPartViewFrame;\
self.currentPartView.view.frame = nextPartViewFrame;\
}\
completion:^(BOOL finished) {\
self.currentPartNumber = 1;\
self.navBarView.prevButton.enabled = NO;\
self.navBarView.nextButton.enabled = YES;\
[self.previousPartView.view removeFromSuperview];\
self.previousPartView = nil;\
if (self.currentPartView.showsShareOptions == YES) {\
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Share" style:UIBarButtonItemStyleBordered target:self action:@selector(shareButtonPressed:)];\
}\
}\
];\
在CodeReview中,要求清理代碼的最佳位置將結束。 http://codereview.stackexchange.com/questions – nhgrif