« Q&A: June 21, 2002
// Question One
I would like to have an arrow at the bottom of my window such that when pressed will point down and the window will extend, and I can put a text view within the extended part. I've seen this in many applications. How do they do this? Do they extend the view? Do they create another view below the current view?
Changing the window size: Easy. Check the docs on NSWindow's -setFrame:display:animate:
Showing the view: One simple way to do this if the window will expand downward. Set your content view to be a view that uses flipped coordinates (hint, check NSView's -isFlipped method). This is important because it will cause the view to lay out from the top rather than from the bottom. This will allow your window to expand downward without shifting the contents of your view. Now, fill in the view as if it were expanded and set the initial size of the window so it hides the bottom part.
The benefit of this approach is that you can change the size of your view and change its contents in anyway you want regardless of whether or not the bottom part is supposed to be visible.
The arrow control: I don't believe AppKit comes with one of these prebuilt. It would be very easy to create one of these, though. It took me fifteen minutes to add it to some custom view on my project.
answer by: Charles Jolley on cocoa-dev mailing list.
// Question Two
When I build my program I get cryptic errors saying that my app "depends on itself". After that I get "don't know how to make" errors. What's the problem?
The "depends on itself" warning is meaningless and will go away in a future release. The problem is the first "don't know how to make" or other such error. Not knowing how to make a source file implies a bad reference. Use Show Info after selecting the source file in the Files panel and check if the reference is in red, and in the case of source files if they can be edited. In some cases it may also be helpful to use Show Info on the project at the top of the Files panel to rebuild the index. Also, datestamps before 1970 can happen, on portables in particular, and cause this problem if used for builds.
answer by: Christian Molick on cocoa-dev mailing list.
// Question Three
My document based app keeps opening a brand new blank document whenever it is opened, or if there is no document open, it will make a new one when switching to it. Is there any way to prevent this from happening?
This is the required behavior according to Apple's guidelines. However, see
Invoked immediately before opening an untitled file. Return NO to prevent the application from opening an untitled file; return YES, otherwise. Note that applicationOpenUntitledFile: is invoked if this method returns YES.
answer by: Erik Buck on cocoa-dev mailing list.
// Question Four
What regular expression libraries are available for use?
OSX includes Henry Spencer's regex engine. Just do a 'man regex', it is very simple to use. I've had some problems with the GNU rx library in the past, but they should be solved now thanks to OSX 10.1 two-levels namespaces. PCRE, my personal favourite, compiles under OSX without a single problem (http://www.pcre.org). It is also very easy to use, very powerful and really fast.
answer by: Luc Heinrich on cocoa-dev mailing list.
// Question Five
What good tools are available for searching developer docs offline?
I STRONGLY suggest that you grab MTLibrarian or Marshmellow Librarian (both are listed in Softrak). Index the docs, sample code with that, and you have a really useful search capability.
answer by: Scott Anguish on cocoa-dev mailing list.
// Question Six
My question is this: I have a button that I would like to perform one action when pressed, and another different action when pressed in combination with the Option key. For example, increment a text field value when pressed, but decrement the value when option-pressed.
Connect the button to an action, and check the modifier bits of the currentEvent inside that action. AFAIK there is no way to do that directly in IB (unless you write your own palette, which would contain basically the aforementioned code, for that).
answer by: Ondra Cada on cocoa-dev mailing list.
// Question Seven
Is there any way to document Objective-C code similar to the javadoc method in Java? How do most folks document their code? Was the Cocoa API documentation prepared purely by hand?
The Cocoa API doc does not currently use any kind of JavaDoc-like functionality. However, Apple does have HeaderDoc for C and C++, and we have a first pass of Objective-C functionality in place. You can find out about HeaderDoc, an Open Source tool, here.
answer by: Ron Hayden on cocoa-dev mailing list.
// Question Eight
Is there a Mac OS X equivalent to the gethrtime() nanosecond counter found on Solaris?
From the Mac OS X 10.1 Release Notes:
IMPORTANT: Processes requiring high resolution processor based timing information should use the one of the high level abstractions provided by Mac OS X such as mach_absolute_time or UPTime and should never attempt to access the hardware directly.
Check out /usr/include/mach/mach_time.h and clock.h in the Kernel.framework.
answer by: Brendan Younger on cocoa-dev mailing list.
// Question Nine
Are there any ways to access QuickTime from Cocoa/Objective-C?
QTKit is a project to make QuickTime fully accessible to Cocoa programmers. It will consist of a mix of Cocoa wrappers around sample code from Apple and MacTech and contributed code. I hope to eventually implement all of QTUtilities.c and much more. QTKitView is the main class which will be extended with categories for each various levels of functionality so developers can build the framework with only what they need.
Check out QTKit here.
answer by: Chris Gehlker on cocoa-dev mailing list.
// Question Ten
Has Apple released any interesting sample code lately?
Of course! If you are looking for an example of command-line wrapping (don't forget to check out our articles on Cocoa Dev Central, too), then you might be interested in this:
Cocoa - Moriarity: This sample shows how to implement a Cocoa GUI that wraps command-line functionality, calling out to a UNIX task and presenting the results in the GUI. Sample code available here.