« Q&A: March 16, 2002

Posted by Jeff Hunter on March 16, 2002 [Feedback (0) & TrackBack (0)]

// Question One

I have an NSTabView with multiple tabs. In Interface Builder, how do I add a new tab in the first position?


Select the newly added tab and use the left arrow key to move it to the leftmost position.

answer by: Bill Cheeseman on cocoa-dev mailing list.


// Question Two

Is there some way to get an OS X machine to (reversibly) boot straight into console mode?


You can set the verbose boot flag (how to do this depends on which Open Firmware flavor you have) and edit /etc/ttys to uncomment the line right before the loginwindow line and comment out the loginwindow line. If you don't set the verbose boot flag, the SystemStarter will launch the WindowServer and the /etc/ttys change will cause the system to be stuck at a blue screen...

For detailed information about setting the verbose boot flag in Open Firmware, check this page.

answer by: Matt Watson


// Question Three

I know that there's a way to get IB to generate stub code to instantiate the NIB files, but is there anything like an XML import or export facility?


Yes, it's called nibtool (see "man nibtool" from a terminal).

answer by: Andreas Monitzer


// Question Four

When I read the developer documentation I sometimes see the term "opaque reference." What does this mean and what's the difference from a plain reference?


It means it's a way to refer to something, and you're not supposed to know the details of what it refers to. Or how it refers (it might now be an index into an array, a pointer, a handle, an offset, or whatever). This is different from a pointer to a struct, which is how the Mac toolbox used to be.

answer by: David Dunham


// Question Five

When I have code inside a bundle and want to access resources contained in it, how would I get the path info for it? [NSBundle mainBundle] gives me the main app, not the bundle...


[NSBundle bundleForClass:[self class]]

answer by: Andreas Monitzer


// Question Six

How do I detect which object has been freed when encountering the freed object exception?




answer by: Matt Watson


// Question Seven

When you copy an object. Eg,

stringB = [stringA copy];

Does this automatically autorelease stringB or is this just like doing

stringB = [[NSString alloc] initWithString: stringA];



-copy does not return an autoreleased object. -copy returns a copy of the object with a retain count of 1, but, in the case of immutable objects and -copy, -copy will do [stringA retain] instead of copying the object if stringA is an immutable string. So to answer your question: no, copy does not return an autoreleased object, and yes, in most cases -copy is similiar to the second assignment statement.

answer by: David P. Henderson


// Question Eight

What can I do to catch a keyboard shortcut even if my application isn't in foreground?


The Carbon HotKey API will do it (see CarbonEvents.h). It's quite easy to get to work within a Carbon app. However I don't know how to intercept the generated event from Cocoa apps. It is definitely possible; LaunchBar is a Cocoa app that does it. The Carbon technique (registering a Carbon Event handler) did not work in Cocoa when I tried it.

There is also a private hotkey API in Quartz but it isn't necessary to use it.

For more information see this article by Objective Development.

answer by: Andreas Monitzer


// Question Nine

My app is crashing with signals SIGBUS (signal 10) and SIGSEGV (signal 11). What does this mean?


A bit of trivia: on Mac OS X, both signals are caused by illegal memory accesses; an attempt to access an address that is not mapped at all causes a SIGSEGV ("Segmentation fault"), while an attempt to perform an operation inconsistent with a memory region's protection (e.g., writing to memory mapped read-only) causes a SIGBUS ("Bus error"). The names are historic.

While in theory it is possible to catch these signals and handle them, it certainly is not possible to simply ignore them. In practice, these signals are the sign of a bug in your app, typically an invalid pointer, and you need to fix it.

answer by: Douglas Davidson on cocoa-dev mailing list.

Post a comment