1,刨根問底 self super
知識(shí)點(diǎn):
1,super 結(jié)構(gòu)體
struct objc_super {
__unsafe_unretained id receiver;
__unsafe_unretained Class super_class;
};
2钳宪,class 默認(rèn)實(shí)現(xiàn)
- (Class)class {
return object_getClass(self);
}
3,重寫class 調(diào)用類方法不會(huì)遞歸
@implementation Father
- (Class)class{
return [Father class];
}
@end
2扳炬,Run Loop 記錄與源碼注釋 or iOS底層原理總結(jié) && 細(xì)節(jié)說明
Run Loop 知識(shí)點(diǎn):
1吏颖,CFRunLoopPerformBlock,如果符合當(dāng)前運(yùn)行模式,則下一個(gè)運(yùn)行時(shí)運(yùn)行
2恨樟,如果運(yùn)行模式不一致半醉,不會(huì)強(qiáng)制切換模式,會(huì)等到下一個(gè)模式促發(fā)的運(yùn)行
kCFRunLoopDefaultMode 模式下執(zhí)行CFRunLoopPerformBlock厌杜,會(huì)一致等UITrackingRunLoopMode促發(fā)才執(zhí)行下面代碼
CFRunLoopPerformBlock(CFRunLoopGetCurrent(), (CFStringRef)UITrackingRunLoopMode, ^{
[self test];
});
- (void)test{
if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) {
NSLog(@"cjw cjw isMainQueue");
}
}
3奉呛,isEqual & hash
1,isEqual 需要重寫
2夯尽,hash 需要重寫
4,MainQueue or MainThread
1登馒,主隊(duì)列(MainQueue)里面block 一定都在主線程執(zhí)行匙握。
GCD中將任務(wù)提交到主線程的主隊(duì)列即dispatch_get_main_queue()時(shí),這里的任務(wù)是由RunLoop負(fù)責(zé)執(zhí)行陈轿。RunLoop和線程綁定圈纺。所以上面結(jié)論沒毛病秦忿。
試試下面代碼
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSLog(@"cjw cjw %@",[NSThread currentThread]);
dispatch_sync(dispatch_get_main_queue(), ^{
NSLog(@"cjw cjw %@",[NSThread currentThread]);
});
});
2,主線程(MainThread)不一定都在MainQueue里面執(zhí)行
下面這段代碼說明MainThread可以在其他Queue里面執(zhí)行
dispatch_queue_t queue = dispatch_queue_create("testQueue", DISPATCH_QUEUE_SERIAL);
dispatch_sync(queue, ^{
if ([NSThread isMainThread]) {
NSLog(@"cjw cjw is mainthread");
}
if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) {
NSLog(@"cjw cjw isMainQueue");
}
});