更新时间:2017-04-13 来源:黑马程序员iOS学院 浏览量:
1 | static const NSTimeInterval kAnimationDuration = 0.3; |
1 | NSString *const UIApplicationDidEnterBackgroundNotification |
1 2 3 4 5 |
typedef enum : { CameraModeFront, CameraModeLeft, CameraModeRight, } CameraMode; |
1 2 3 4 5 6 7 |
typedef NS_ENUM(NSInteger, UIViewAnimationTransition) { UIViewAnimationTransitionNone, UIViewAnimationTransitionFlipFromLeft, UIViewAnimationTransitionFlipFromRight, UIViewAnimationTransitionCurlUp, UIViewAnimationTransitionCurlDown, }; |
1 2 |
titleLabel //表示标题的label, 是UILabel类型 confirmButton //表示确认的button, 是UIButton类型 |
1 2 |
if (someObject) { ... } if (!someObject) { ... } |
1 2 |
if (someObject == YES) { ...} if (someObject != nil) { ...} |
1 | result = object ? : [self createObject]; |
1 | result = object ? object : [self createObject]; |
1 2 3 4 |
NSArray *names = @[@"Brian", @"Matt", @"Chris", @"Alex", @"Steve"]; NSDictionary *productManagers = @{@"iPhone" : @"Kate", @"iPad" : @"Kamal"}; NSNumber *shouldUseLiterals = @YES; NSNumber *buildingZIPCode = @10018; |
1 | @property (nonatomic, readwrite, copy) NSString *name; |
1 | BOOL isAdult = age > 18; |
1 2 3 4 5 6 7 8 9 |
BOOL isAdult; if (age > 18) { isAdult = YES; } else { isAdult = NO; } |
1 2 3 |
if (car == Car.Nissan) or const int adultAge = 18; if (age > adultAge) { ... } |
1 2 3 |
if (carName == "Nissan") or if (age > 18) { ... } |
1 2 3 4 5 6 7 8 9 10 11 |
if ([self canDeleteJob:job]) { ... } - (BOOL)canDeleteJob:(Job *)job { BOOL invalidJobState = job.JobState == JobState.New || job.JobState == JobState.Submitted || job.JobState == JobState.Expired; BOOL invalidJob = job.JobTitle && job.JobTitle.length; return invalidJobState || invalidJob; } |
1 2 3 4 5 6 7 |
if (job.JobState == JobState.New || job.JobState == JobState.Submitted || job.JobState == JobState.Expired || (job.JobTitle && job.JobTitle.length)) { //.... } |
1 2 3 4 5 |
if (!user.UserName) return NO; if (!user.Password) return NO; if (!user.Email) return NO; return YES; |
1 2 3 4 5 6 7 8 9 10 11 12 |
BOOL isValid = NO; if (user.UserName) { if (user.Password) { if (user.Email) isValid = YES; } } return isValid; |
1 2 3 4 5 6 |
- (void)registerUser(User *user) { // to do... } |
1 2 3 4 5 6 |
- (void)registerUserName:(NSString *)userName password:(NSString *)password email:(NSString *)email { // to do... } |
1 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; |
1 2 3 4 5 6 |
__weak typeof(self) weakSelf = self; dispatch_block_t block = ^{ [weakSelf doSomething]; // weakSelf != nil // preemption, weakSelf turned nil [weakSelf doSomethingElse]; // weakSelf == nil }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
__weak typeof(self) weakSelf = self; myObj.myBlock = ^{ __strong typeof(self) strongSelf = weakSelf; if (strongSelf) { [strongSelf doSomething]; // strongSelf != nil // preemption, strongSelf still not nil [strongSelf doSomethingElse]; // strongSelf != nil } else { // Probably nothing... return; } }; |