Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSLog(@"%@",super) crashing

I used NSLog(@"%@",super) in a method(any method) and it is crashing.... Why? How to print the super contents?

Updated :

currentclassname : superClassName
{
}

and also if i use NSLog(@"%@", [super description]); It is printing "<currentclassname: 0x3db7230>" instead of superClassName... It is expected to print superClassName right.

Thanks in advance,

like image 283
Chandan Shetty SP Avatar asked Nov 25 '25 21:11

Chandan Shetty SP


2 Answers

When encountering the keyword super and a method call on it, the compiler generates a different call - objc_msgSendSuper*() instead of the usual objc_msgSend*().

objc_msgSendSuper*() calls get an argument of type objc_super* instead of objc_object*:

struct objc_super {
   id receiver;
   Class class;
};

So, objc_super* values aren't special instances, they have to be used with the special objc_msgSendSuper*() functions.

Thus, as Alex says, just call -description directly on super - its value is meaningless outside of the context its in unless you specifically use it with a runtime function like objc_msgSendSuper().

like image 166
Georg Fritzsche Avatar answered Nov 28 '25 16:11

Georg Fritzsche


Use -description, e.g.:

NSLog(@"%@", [super description]);

If you have access to the superclass, you can override its -description method to return whatever information you want, or perhaps augment the class with a category.

like image 31
Alex Reynolds Avatar answered Nov 28 '25 16:11

Alex Reynolds



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!