2014年5月22日 星期四

盡量不要用#define來定義key的文字

應該要改用const NSString以避免可能發生文字覆蓋的錯誤
例如:
.h檔
#import <Foundation/Foundation.h>
extern NSString *SelectionSort;
extern NSString *InsertionSort;
extern NSString *BubbleSort;
@interface Algorithm : NSObject
@end

.m檔
#import "Algorithm.h"
@implementation Algorithm
const NSString *SelectionSort = @"SelectionSort";
const NSString *InsertionSort = @"InsertionSort";
const NSString *BubbleSort    = @"BubbleSort";

@end

沒有留言:

張貼留言