常用代碼片段
GCD:僅執(zhí)行一次
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
_sharedManager = [[self alloc] init];
});
常量的聲明
// .h中聲明
/** Posted when a task resumes. */
FOUNDATION_EXPORT NSString * const AFNetworkingTaskDidResumeNotification;
// .m中賦值
NSString * const AFNetworkingTaskDidResumeNotification = @"com.alamofire.networking.task.resume";
或
static NSString * const AFURLSessionManagerLockName = @"com.alamofire.networking.session.manager.lock";
static NSTimeInterval const kDefaultAFNetworkActivityManagerActivationDelay = 1.0;
向RunLoop中添加Timer
// 添加
_activationDelayTimer = [NSTimer timerWithTimeInterval:self.activationDelay target:self selector:@selector(activationDelayTimerFired) userInfo:nil repeats:NO]; //Q:為什么此處的repeats為NO呢大年?
[[NSRunLoop mainRunLoop] addTimer:_activationDelayTimer forMode:NSRunLoopCommonModes];
// 移除
[_activationDelayTimer invalidate];
注:讓需要將Timer從RunLoop中移除時(shí),直接調(diào)用-invalidate
方法就好了~
(該方法的說明為“Stops the receiver from ever firing again and requests its removal from its run loop.”)
-setNeedsLayout; 與-layoutIfNeeded; 的區(qū)別
- (void)setNeedsLayout;
:無效當(dāng)前的布局今妄,并在下一個視圖更新周期期間觸發(fā)布局更新实蓬。由于這種方法不強(qiáng)制立即更新布局,而是等待下一個更新周期,在許多視圖更新布局之前你可以使用它將這些布局無效化褒颈。這種行為可以讓你將所有布局的更新整合到一個更新周期,這通常是更好的性能励堡。
- (void)layoutIfNeeded;
:立刻布局子視圖谷丸。使用此方法在布局繪制前來強(qiáng)制布局子視圖。
未完待續(xù)...