Objective-C基础学习之Super关键字

1.super基本概念

  • 【Objective-C基础学习之Super关键字】super是个编译器的指令符号,只是告诉编译器在执行的时候,去调谁的方法.
    • self是一个隐私参数;
self refers to the object receiving a message in objective-C programming.

  • super 并不是隐藏的参数,它只是一个“编译器指示符”,它和 self 指向的是相同的消息接收者
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.

2.super的作用
+ 1.直接调用父类中的某个方法 + 2.super在对象方法中,那么就会调用父类的对象方法 super在类方法中,那么就会调用父类的类方法

  • 使用场合:
    • 子类重写父类的方法时想保留父类的一些行为

    推荐阅读