• Working with Pascal Strings in Cocoa

    Posted on August 23rd, 2007 Alan 2 comments

    In trying to access information from a quicktime file I came across my first pascal string (pstring).  Trying to copy this string using strncpy or NSString:stringWithCString did not work so I looked at the memory and saw a number as the first byte.  I recognized this as a pascal string so I searched on conversion from pstring to NSString and found this:

    http://www.omnigroup.com/mailman/archive/macosx-dev/2001-August/030492.html
    http://developer.apple.com/documentation/CoreFoundation/Reference/CFStringRef/Reference/reference.html#//apple_ref/c/func/CFStringCreateWithPascalString

    The documentation for CFString states: "in a method where you see an NSString * parameter, you can pass in a CFStringRef" but the compiler complained so as in the example code linked above, I resorted to using the NSString:stringWithFormat. My first thought was to simply use NSString:stringWithString.

    Here is the wrapper function I came up with:

    -(NSString*)NSStringFromPString:(unsigned char*) pstring
    {
        CFStringRef strRef = CFStringCreateWithPascalString (NULL, pstring, kCFStringEncodingMacRoman);
        return [NSString stringWithFormat:@"%@",strRef];
    }

    Update 8/24/07: It seems the error when using stringWithString has something to do with what source is being compiled.  If it is in an .mm file (enables C++ compatibility?) I get the error:

    error: cannot convert ‘const __CFString*’ to ‘NSString*’ in argument passing

    but if compiled in an .m file it works fine.  It appears that in the former case, the compiler is being stricter, though a forced cast will eliminate the error message.

  • Mac Documentation, not so good

    Posted on August 23rd, 2007 Alan No comments

    I’ve given the Development Documentation for XCode a few weeks, but yesterday, after spending half a day searching how to retrieve the Codec information from a quicktime file, I finally concluded that the best source of documentation is source code on the web.  With the lack of examples the documentation is only of minimal help when you are new and trying to discover HOW to do things, not just reference information.

    Two sites helpful in searching code are Krugle and Koder.  Krugle has a nicer UI. I haven’t used Koder much.

  • Obscure compile/link errors on the Mac

    Posted on August 10th, 2007 Alan No comments

    Xcodd 2.4.1:

    Error:
    Undefined symbols:
    vtable ClassName
    Solution:
    Make sure you have implemented all members of your class.  I had forgotten to implement my destructor

  • Mixing Objective-C with C++

    Posted on August 10th, 2007 Alan No comments

    It seems mixing Objective-C code with C++ code is pretty straight forward:

    Mixing Objective-C and C++ Language Feautures

    The key is naming your objective-c files with a .mm extension. Here is a thread that talks about file naming and other tips.

    Chris discusses C++ objects as Objective-C instance variables and points to this thread.

  • Listing folders first in Finder column view

    Posted on August 8th, 2007 Alan No comments

    I have to agree with this thread regarding the order of folders/files in Finder.  I much prefer seeing a list of folders at the top followed by the files.  I like the idea someone posted of preceeding folder names with an underscore to force them to the top. I may do that.

  • Cocoa Development Resources

    Posted on August 6th, 2007 Alan No comments

    Objective-C guide for C++ programmers?  Sign me up.

    Objective-C overview

    XCode Tools Tips

    Cocoa Framework Summary

    Debugging Techniques

  • General Mac tips

    Posted on August 6th, 2007 Alan No comments

    Managing desktop

    Use Expose to help access open windows: System Preferences…Dashboard & Expose.  I use the upper left corner of the screen to show all windows and the lower left corner to view desktop.

    Keyboard shortcuts

    <fn><delete> will do a forward delete
    <fn><option><delete> deletes word to right of cursor
    <Left Arrow>/<Right Arrow> to open/close folders in finder
    Cmd+[, Cmd+] to move backward and forward in finder history

    Secrets Preferences Pane – turn on showing of hidden files in finder and much more

    How to Print Screen to a file on the desktop in Mac OS X

    The basic functionality of taking a screen capture of a window or desktop in Mac OS X takes an image and dumps it to a file on the Mac desktop. Each uses the pressing of Command and Shift keys concurrently as the basis for execution, followed by a number:

    • Command+Shift+3: takes a screenshot of the full screen (or screens if multiple monitors), and save it as a file to the desktop
    • Command+Shift+4: brings up a selection box so you can specify an area to take a screenshot of, then save it as a file to the desktop
    • Command+Shift+4, then spacebar, then click a window: takes a screenshot of a window only and saves it as a file to the desktop

    How to Print Screen to the Clipboard on a Mac

    This functions a lot more like Print Screen in the Windows world. If you want to do the equivalent of Print Screen to the clipboard so that you can paste it into another app, these are the commands you’d want to use:

    • Command+Control+Shift+3: take a screenshot of the entire screen (screens if multiple monitors), and saves it to the clipboard for pasting elsewhere
    • Command+Control+Shift+4, then select an area: takes a screenshot of selection and saves it to the clipboard for pasting elsewhere
    • Command+Control+Shift+4, then space, then click a window: takes a screenshot of a window and saves it to the clipboard for pasting
  • XCode Project Window Layouts

    Posted on August 6th, 2007 Alan No comments

    It took me a while to find this so I’m posting it so I don’t forget.  Before I got my MacBook I was using a Mac Pro workstation with XCode already installed.  It had a control in the toolbar titled "Page" with three options: Project, Build, and Debug.

    When I installed XCode on my MacBook I lost the ability to switch between layouts.  One of the things I don’t like working with XCode is how so many windows end up being displayed and the difficulty in finding and switching between them.  The problem is exacerbated by the fact the MIB Editor is a separate program which is not integrated with the XCode environment.  It’s too bad this All-In-One layout isn’t used by default, I may not have had such a bad first impression of the XCode UI.

    I finally found how to restore my preferred 3-layout mode.  Simply select All-In-One Layout in the General tab of the XCode Preferences.  BTW, I searched using Google for "Customizing page control in XCode" to find this Apple documentation.  I had found in the View menu "Show Page Control" which gave me a clue but the default page control only gives you Project & Morph.  I though it odd that a control that has it’s own menu item, and that can contain different items, couldn’t be customized on it’s own.

  • What I don’t like about my new MacBook Pro

    Posted on August 6th, 2007 Alan 2 comments

    Not much, but since I’m being real:

    I prefer to use an attached mouse when I’m working at the office.  An inexpensive USB optical 3 button mouse with a scroll wheel will do nicely.  Please, no 1-button Apple mice.  The convenience of a right button for context menus, and scrollwheel for scrolling can’t be beat.

    My workarea arrangement has just enough space for a mousepad to the right of the MacBook.  I also must have a second screen attached.  I don’t like the connections along the right side of the MacBook.  Attaching the DVI/VGA connector interferes with my placement of the mousepad and use of a mouse.  I actually attach the mouse to the USB port on the left side and bring it around the back to the right side.  The ethernet port is on the right side too which also gets in the way.  If the connections could have been placed in the back, all cabling would have been hidden and would have allowed for more work space.

    That’s basically it. Certainly a lot more to like than not like.

  • Cocoa Development Book Recommendations

    Posted on August 1st, 2007 Alan No comments

    I received a nice reading list recommendation via email in response to this first post on Mac Development.  Here is the recommendation:

    Kochan’s, "Objective C" is a great book. On the other hand, Garfinkle and Mahoney is very much out of date to the point that many in the community are upset that O’Reilly still sells the book without a caveat. The Cocoa they were writing about is circa 2000 or 2001. A great deal, mainly from Tiger and even Jaguar, has changed since then.

    A better book would be Aaron Hillegass’, "Cocoa Programming for Mac OS X", 2nd ed. Aaron’s book is based on his Cocoa Bootcamp, an intense week of A-Z in Cocoa programming. Although a bit long in the tooth, though not as much as G & M, Anguish and Yacktman’s, "Cocoa Programming" is a great tome for filling in
    the details that Aaron may gloss over. And no book recommendation would be worth much without mentioning, "Cocoa Recipies for OS X’ by Cheeseman.

    Also recommended by a friend: Advanced Mac OSX Programming – by Mark Dalrymple