51

As far as I know, it's a pointer to the superclass. It's hard-wired with the superclass, and not dynamically figured out at runtime. Would like to know it more in detail...

Anyone?

Ben S
  • 68,394
  • 30
  • 171
  • 212
dontWatchMyProfile
  • 45,440
  • 50
  • 177
  • 260

4 Answers4

49

super

Essentially, it allows you to use the implementations of the current class' superclass.

For the gritty details of the Objective-C runtime:

[super message] has the following meaning:

When it encounters a method call, the compiler generates a call to one of the functions objc_msgSend, objc_msgSend_stret, objc_msgSendSuper, or objc_msgSendSuper_stret. Messages sent to an object’s superclass (using the super keyword) are sent using objc_msgSendSuper; other messages are sent using objc_msgSend. Methods that have data structures as return values are sent using objc_msgSendSuper_stret and objc_msgSend_stret.

So yes, it is static, and not determined at runtime.

Ben S
  • 68,394
  • 30
  • 171
  • 212
  • Possibly cause for a new question, but `super` behaves oddly (or "normally", if you think that way) in categories. That is, it treats the category as a subclass (not an override), so `super` is then the original, unmodified class. Sort of. Sometimes. "It's complicated." – Olie Jul 31 '14 at 01:13
  • "gritty" "details" - links are dead – Darren Ng Mar 04 '21 at 18:11
29

It's a keyword that's equivalent to self, but starts its message dispatch searching with the superclass's method table.

Chuck
  • 234,037
  • 30
  • 302
  • 389
20

super is not a pointer to a class. Super is self, but when used in a message expression, it means "look for an implementation starting with the superclass's method table."

NSResponder
  • 16,861
  • 7
  • 32
  • 46
6

These blog postings on what is a meta class?, getting subclasses and classes and metaclasses may give you some insight on the internals of this.

David Gelhar
  • 27,873
  • 3
  • 67
  • 84