读书笔记

Effictive Objective - C 2.0读书笔记(

2016-01-06  本文已影响156人  庸者的救赎

Accustoming Yourself to Objective - C

Minimize Importing Headers in Headers

Prefer Literal Syntax over the Equivalent Methods

Prefer Typed Constants to Preprocessor #define

// 不推荐
#define ANIMATION_DURATION 0.3 
// 推荐,并且已定要同时使用static和const修饰符.
static const NSTimeInterval kAnimationDuration = 0.3; 
extern NSString *const EOCStringConstant;

// 实现文件中
NSString *const EOCStringConstant = @"VALUE";

Use Enumerations for States,Options,and Status Codes

Understand Properties


@interface EOCPerson : NSObject
{
    // instance variables
    NSString *_fullName;
    NSString *_sex;
}

// property
@property (nonnatomic, copy) NSString *firstName;
@property (nonnatomic, copy) NSString *lastName;

@end

两种写法有以下几点不同

推荐按如下方式使用

Understand Object Equality

上一篇 下一篇

猜你喜欢

热点阅读