Sweet, Sweet Cocoa

SO SWEET!

Posts tagged objc

0 notes &

Pay No Attention to the Runtime Behind the Curtain

You can get a good idea of the complexity of the Objective-C runtime behind the scenes by using clang with the -rewrite-objc option. This simple line to allocate and initialize an NSArray with a few NSString literals
keysArray = [[NSArray alloc] initWithObjects:@"period", @"mass", @"meanAnomaly", @"eccentricity", @"longPeri", nil];

would become something like this ungodly mess, if there were a separate “compile to C” step:

keysArray = ((id (*)(id, SEL, id, ...))(void *)objc_msgSend)((id)((id (*)(id, SEL))(void *)objc_msgSend)
	(objc_getClass("NSArray"), sel_registerName("alloc")), sel_registerName("initWithObjects:"), 
	(id)(NSString *)&__NSConstantStringImpl_OKOrbitalFit_m_0, (NSString *)&__NSConstantStringImpl_OKOrbitalFit_m_1, 
	(NSString *)&__NSConstantStringImpl_OKOrbitalFit_m_2, (NSString *)&__NSConstantStringImpl_OKOrbitalFit_m_3, 
	(NSString *)&__NSConstantStringImpl_OKOrbitalFit_m_4, ((void *)0));
Enough to bring down cdecl.

Filed under objc