少用#define预处理指令
//不要用预处理指令定义常量。这样定义出来的常量不含类性信息,编译器只是会在编译
//前据此执行查找与替换操作。即使有人重新定义了常量值,编译器也不会产生警告信息,
//这将导致应用程序中的常量值不一致
#define ANIMATION_DURATION 0.3
static const “只在编译单元内可见的常量”
//
// EOCAnimatedView.h
// iOS
//
// Created by wu on 15/6/7.
//
#define NSTimeInterval float
#import <UIKit/UIKit.h>
@interface EOCAnimatedView : UIView
- (void)animation;
@end
//
// EOCAnimatedView.m
// iOS
//
// Created by wu on 15/6/7.
//
#import "EOCAnimatedView.h"
@implementation EOCAnimatedView
//在实现文件中使用static const来定义“只在编译单元内可见的常量”。由于此常量不在全
//局符号表中,所以无须为其名称加前缀
static const NSTimeInterval kAnimationDuration = 0.3f;
- (void)animation
{
}
@end
const 全局常量
//
// EOCLoginManager.h
// iOS
//
// Created by wu on 15/6/7.
//
#import <Foundation/Foundation.h>
//申明
extern NSString *const EOCLoginManagerDidLoginNotification;
@interface EOCLoginManager : NSObject
@end
//
// EOCLoginManager.m
// iOS
//
// Created by wu on 15/6/7.
//
#import "EOCLoginManager.h"
//定义
NSString *const EOCLoginManagerDidLoginNotification = @"EOCLoginManagerDidLoginNotification";
@implementation EOCLoginManager
@end