美文网首页
iOS面试题中的self 与 super

iOS面试题中的self 与 super

作者: bigCatloveFish | 来源:发表于2018-08-10 20:47 被阅读8次
@implementation Son
- (instancetype)init{
    if (self = [super init]) {
        NSLog(@"%@",NSStringFromClass([self class]));
        NSLog(@"%@",NSStringFromClass([self superclass]));
        NSLog(@"%@",NSStringFromClass([super class]));
        
    }
    return self;
}
@end

这个问题主要是 self 和super

self refers to the object receiving a message in objective-C programming.

super is a flag that tells the compiler to search for the method implementation in a very different place. It begins in the superclass of the class that defines the method where super appears.

self 是从当前类开始找 super 是从 父类开始找。最后接受者 都是当前对象。所以返回的是一样的。

最后都返回 son father son

  1. @property 默认的数据类型
@property NSMutableArray *arr ;
@property int zz;

对应基本数据类型,默认关键字为
atomic, assign, readwrite
对应对象类型,默认关键字为
atomic, strong, readwrite
atomic 与 nonatomic 区别 读写安全。
atomic 确保 读写安全。会在set 之后读取数据。若多线程同时set 不确保最后读取数据的准确性。

相关文章

  • iOS面试题中的self 与 super

    这个问题主要是 self 和super self 是从当前类开始找 super 是从 父类开始找。最后接受者 都是...

  • iOS self 与 super

    下面是一道面试题 问运行程序,打印的结果是什么? class 方法 clang 一下 Son.m 文件可以看出来 ...

  • Objective-C self与super的区别

    Objective-C self与super的区别 [self class] 和 [super class] 在当...

  • if(self=[super init]) 为什么加if

    if(self=[super init])为什么不用“==”而用“=”: 这里不是判断self与[super in...

  • iOS中self与super

    一.self关键字OC语言中的self,就相当于C++、Java中的this指针 在整个程序运行过程中,一个类有且...

  • iOS中self与super

    一.self关键字 OC语言中的self,就相当于C++、Java中的this指针 1.类方法中的self...

  • iOS  self  super

    @implementation Son : Father - (id)init { self = [super...

  • iOS面试题 - Runtime

    1、self和super self和super是经常在面试中被问到的,而且有一段典型的代码如下: 执行结果都为So...

  • Runtime源码

    1 self/super与NSObject对象 self, super不计算在object的size里面,用cla...

  • 面试题分析

    面试题一: [self class] & [super class] 以下打印输出什么? 直接运行,? [self...

网友评论

      本文标题:iOS面试题中的self 与 super

      本文链接:https://www.haomeiwen.com/subject/hmvkbftx.html