search

Home  >  Q&A  >  body text

objective-c - 在一个父类中 self 是其子类的对象.


在一个类的父类中什么情况下 self 可以表示为它的子类的对象?self 不应该是在哪个类中表示那个类的对象吗?

黄舟黄舟2852 days ago736

reply all(2)I'll reply

  • 某草草

    某草草2017-05-02 09:20:51

    The self keyword in iOS has many meanings and rules. It does not mean which class of object it refers to in which class the subject understands! First of all, correct this problem. Self represents the object of the current class. In the picture posted by the subject, the type of the current object is displayed, which can be understood as calling [self class]. If the current class and all parent classes have not overridden this method, Then the class method of NSObject will be called.

    In addition, the self keyword in OC has different meanings and functions in different scopes. In instance methods, self represents the first address of the object, while in class methods, self represents the current Class. In OC, Class is also an object, so self is different,

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-02 09:20:51

    When that object is really a subclass object

    reply
    0
  • Cancelreply