面试合集iOS归纳

4. iOS面试题原理篇2

2020-12-02  本文已影响0人  越天高

lldbgdb)常用的调试命令?

BAD_ACCESS在什么情况下出现?

如何调试BAD_ACCESS错误

• 开启僵尸对象调试功能


Edit Scheme.png Arguments.png

简述下Objective-C中调用方法的过程(runtime

什么是method swizzling(俗称黑魔法)

• 每个类都有一个方法列表,存放着方法的名字和方法实现的映射关系,selector的本质其实就是方法名,IMP有点类似函数指针,指向具体的Method实现,通过selector就可以找到对应的IMP


selectorA.jpeg

* 交换方法的几种实现方式

◦ 利用 method_setImplementation 来直接设置某个方法的IMP

selectorA.jpeg

objc中向一个nil对象发送消息将会发生什么?

    struct objc_class
*   {
*   // isa指针指向Meta Class,因为Objc的类的本身也是一个Object,
*   // 为了处理这个关系,runtime就创造了Meta Class,
*   // 当给类发送[NSObject alloc]这样消息时,实际上是把这个消息发给了Class Object
*   Class isa OBJC_ISA_AVAILABILITY;
*   #if !__OBJC2__
*   Class super_class OBJC2_UNAVAILABLE; // 父类
*   const char *name OBJC2_UNAVAILABLE; // 类名
*   long version OBJC2_UNAVAILABLE; // 类的版本信息,默认为0
*   long info OBJC2_UNAVAILABLE; // 类信息,供运行期使用的一些位标识
*   long instance_size OBJC2_UNAVAILABLE; // 该类的实例变量大小
*   struct objc_ivar_list *ivars OBJC2_UNAVAILABLE; // 该类的成员变量链表
*   struct objc_method_list **methodLists OBJC2_UNAVAILABLE; // 方法定义的链表
*   // 方法缓存,对象接到一个消息会根据isa指针查找消息对象,
*   // 这时会在method Lists中遍历,
*   // 如果cache了,常用的方法调用时就能够提高调用的效率。
*   // 这个方法缓存只存在一份,不是每个类的实例对象都有一个方法缓存
*   // 子类会在自己的方法缓存中缓存父类的方法,父类在自己的方法缓存中也会缓存自己的方法,而不是说子类就不缓存父类方法了
*   struct objc_cache *cache OBJC2_UNAVAILABLE;
*   struct objc_protocol_list *protocols OBJC2_UNAVAILABLE; // 协议链表
*   #endif
*   } OBJC2_UNAVAILABLE;

objc中向一个对象发送消息[obj foo]和objc_msgSend()函数之间有什么关系?

什么时候会报unrecognized selector的异常?

HTTP协议中POST方法和GET方法有那些区别?

使用block时什么情况会发生引用循环,如何解决?

block内如何修改block外部变量?

使用系统的某些block api(如UIViewblock版本写动画时),是否也考虑循环引用问题?

[UIView animateWithDuration:duration animations:^

{ [self.superview layoutIfNeeded]; }];

[[NSOperationQueue mainQueue] addOperationWithBlock:^

{ self.someProperty = xyz; }];

[[NSNotificationCenter defaultCenter] addObserverForName:@"someNotification"

 object:nil

 queue:[NSOperationQueue mainQueue]

 usingBlock:^(NSNotification * notification)

 { self.someProperty = xyz; }];
*   dispatch_group_async(_operationsGroup, _operationsQueue, ^
*   {
*   [weakSelf doSomething];
*   [weakSelf doSomethingElse];
*   } );
*   __weak __typeof__(self) weakSelf = self;
*   _observer = [[NSNotificationCenter defaultCenter]
*   addObserverForName:@"testKey"
*   object:nil
*   queue:nil
*   usingBlock:^(NSNotification *note){
*   [weakSelf dismissModalViewControllerAnimated:YES];
*   }];

OC中常见的循环引用总结

上一篇 下一篇

猜你喜欢

热点阅读