1.宏定義
// ...表示宏定義的可變參數(shù)
// __VA_ARGS__:表示函數(shù)里面的可變參數(shù)
#ifdef DEBUG
#define QYLog(...) NSLog(__VA_ARGS__)
#else
#define QYLog(...)
#endif
// 偏好設置存儲的好處
// 1.不需要關心文件名
// 2.快速進行鍵值對存儲
// 補充:控制器的view
// UITabBarController控制器的view在一創(chuàng)建控制器的時候就會加載view
// UIViewController的view阶界,才是懶加載春畔。
2.枚舉 enum,NS_ENUM,NS_OPTIONS
在iOS6和Mac OS 10.8以后Apple引入了兩個宏NS_ENUM,NS_OPTIONS來重新定義C語言風格的enum,實際上是將enum定義和typedef合二為一,并且采用不同的宏來從代碼角度來區(qū)分。
enum{
UIViewAnimationTransitionNone,
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
UIViewAnimationTransitionCurlUp,
UIViewAnimationTransitionCurlDown,
} UIViewAnimationTransition;
替換為:
typedef NS_ENUM(NSInteger, UIViewAnimationTransition) {
UIViewAnimationTransitionNone,//默認從0開始
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
UIViewAnimationTransitionCurlUp,
UIViewAnimationTransitionCurlDown,
};
位移操作枚舉定義
enum {
UIViewAutoresizingNone = 0,
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
UIViewAutoresizingFlexibleWidth = 1 << 1,
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
UIViewAutoresizingFlexibleHeight = 1 << 4,
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};
typedef NSUInteger UIViewAutoresizing; // UIViewAutoresizing相當于NSUInteger的一個別名使用疆导。
替換為:
typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
UIViewAutoresizingNone = 0,
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
UIViewAutoresizingFlexibleWidth = 1 << 1,
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
UIViewAutoresizingFlexibleHeight = 1 << 4,
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};