Posts belonging to Category Cocoa



Adding Controls to HUD Windows


Although not intended by apple to have controls, HUD windows can have controls added to them. This is accomplished by any one of the 3 frameworks listed below

  • BWToolkit – http://www.brandonwalkin.com/bwtoolkit/
  • BGHUDAppKit – http://www.binarymethod.com/bghudappkit/
  • HMBlkAppKit – http://shiira.jp/hmblkappkit/en.html
  • Cocoa Recipes updated


    Recently I noticed that one of my favorite books for learning cocoa was updated to it’s second version.  Cocoa Recipes for Mac OS X (2nd Edition) is a hands on approach to teaching cocoa. The orginal Cocoa Receipes was conceived from a web site  from the same author called Vermont Recipes.  This book is one of the best books for driving home some real world learning after finishing Aaron Hillegass book Cocoa(R) Programming for Mac(R) OS X (3rd Edition).  There is nothing better to learning cocoa concepts than actually writing code especially as part of an actual application.

    The entire book takes the reader through development of one complete project. The reader follows along as the author adds new features to the application one chapter at a time.  The author takes the time in each chapter to explain what is happening.   I referenced the Vermont Recipes extensively (before the book came out) when I first picked up cocoa and still find it useful today. The new version is updated to reflect the changes in the recent Snow Leopard OS X release.
    As a side note I should mention that I do not know the author personally or compensated in anyway for writing this post.  Bill Cheeseman is a very active member of the Cocoa community and can be seen on the Apple mailing list.  Also, as of this writing, Amazon’s look inside the index is from the old version.




    Learning C programming with Cocoa

    After almost 12 years of C  programming under my belt I often find myself answering questions from people asking me how to get started.  Most will ask what I think is the one single book to read when learning how to program in C or do I need to know C before I learn other C languages such as Objective C and C++.  There are many avenues to learning how to write in C which can often leave a new comer feeling overwhelmed. However, I think there is one approach that works well and provides a step wise approach to learning C.  Oddly enough, it does not envolve learning traditional C directly.  Learn to program in Apple’s Cocoa language and ease into traditional C.

    For the most part, there is not one book.  Usually it takes 3 or 4 really good books to get a handle on C programming. Each book provides its own unique aspects to teaching, skipping some topics while covering other in depth.  One of the things that I like about using Cocoa as a starting point is instant gradification.  Using Cocoa(R) Programming for Mac(R) OS X (3rd Edition) as a learning tool can provide the new comer with a good sense of how programming works.

    Cocoa is apple’s native way to program for the Mac.  Cocoa utilizes Objective-C as its underlying language.  Objective C is a Object oriented sub set of C much like C++.

    While Cocoa is a great language it is almost impossible to be really good at it or any C dialect without knowing C.  So Why learn Cocoa First?  In short Arron Hillagas’s Cocoa Programming on Mac OS X

    One of the things you will notice is that there are not a lot of books on Cocoa. However, the completeness of Cocoa(R) Programming for Mac(R) OS X (3rd Edition) and the style of Cocoa makes it easy to learn and deduce.  The Cocoa language is so well done syntactically it is very conducive to teaching and Aaron’s book is it’s perfect complement. In my opinion there is not one single book on any language that is as complete from beginner to intermediate as this book.  When you read the text and follow the examples to the end it will leave you comfortable with the language and wanting to learn more into the intermediate level.  With all that said, there are a few must have books that build on the knowledge learned from Aaron’s book.

    If you are interested in learning C through Cocoa here is a list of books I would recommend (In order of learning level). Go here for an easy link to each.

  • Cocoa(R) Programming for Mac(R) OS X (3rd Edition)
  • Learn Cocoa on the Mac (Learn Series)
  • Programming in Objective-C 2.0 (2nd Edition) (Developer’s Library)
  • Learn C on the Mac (Learn Series)
  • Cocoa Programming
  • LibUSB on Mac OS X 10.5.x

    Lately I have been working on two projects to integrate USB hardware with my SerialChannel software. Both of these pieces of hardware have drivers written against libusb. Libusb was born into Linux and provides a portable usb api accross multiple platforms including Windows. On OS X however, it has been a moving target over the years with no central project to keep it going. This has been true until I recently discovered that the folks that maintain the SANE port for various platforms including OS X have also maintained a libusb port as part of their software. The best part is they provide it in a nice and neat SDK package for the various versions of OS X to include Leopard. It takes very little effort to get it going and working in an OS X project.  If you are developing software for a usb device that is recognized by the system as an HID device it will be necessary to create a dummy kext file to prevent OS X HID driver from capturing the device.  When creating the info.plist file do not use IOProbeScore in USB …. EVER or you will get error 2c7. The libusb download link is here. Remember to set environment variable

    prompt$ export DYLD_LIBRARY_PATH=”usr/include/lib:$DYLD_LIBRARY_PATH”

    Serial Port Programming in Cocoa

    I am currently working an a sprinkler controller program that controls a relay board to turn a lawn sprinkler system zones on and off at specific time schedules. One of the interesting things I have learned is serial programming on the Mac. Unlike previous programs I have written I decided to use pure cocoa to communicate with the relay board. The board is 8 output 4 input serial board with an RS232 connection. So, the question is how do I communicate with this board from the mac since there is not a rs232 port on the mac and where is the device file?. On unix system the serial port appears as a device file in the /dev directory. Since the mac does not contain an RS232 port, I am using a usb converter specifically one which provides a virtual com driver for OS X. This driver makes the usb port appear as a serial port and places a device file in the /dev directory. A usb adapter with an FTDI chipset is a perfect example and the one which I am using. As you may or may not know there is not a Apple supplied cocoa classes for accessing the serial port. For a couple of programs I have written, I used the Carbon and C Unix calls to access and use the serial port. However, this is a time consuming task, and would be better suited for my program if I could use or make a cocoa solution. When researching how best to do this in cocoa, I ran across a AMSerialPort. AMSerialPort is a collection of cocoa classes for accessing and doing just about anything with a serial port. It is avaiable here. It also comes with a test application to give you a feel for how to use it. It works really well. The classes also provide a method for accessing a list of available serial ports on the system as well as monitoring the port for incoming data. If you are going to do extensive work in this area The following book provides a good source of information on serial ports.

    Sorry, no items available to list.

    Didn't find what you were looking for?

    Product search

    ...or click here to see similar items.


    SerialChannel 2.1

    Well, it has been a little while since I worked on this application. SerialChannel is a small application I wrote about 1 and 1/2 years ago. It allows Eyetv users to change the channel on a Directv box. The application makes use of a serial cable that connects from the computer to the box (much the same way mythtv works). SerialChannel up to this point required editing 3 settings in the internal perl script to match the users setup. After many request from users to provide a graphical configuration to SerialChannel, I have done so. SerialChannel 2.1 now provides a configuration preferences window which provides a list of serial devices detected, baud rate, and Directv Box for the user to choose and set. I also decided since I was going this far I may as well give trouble shooting a boost as well by providing feedback of errors in the main window. I initially resisted doing this because I wanted to keep the program as simple as possible. I think it is kind of a waste to have a full blown GUI for configuring especially when this is only done once -set it and forget it. Editing the pearl script was really not hard, but in the end I understand everyone has different skill sets. If you have a look at my website for SerialChannel you will see my lack of skills in designing web pages. So if you use Eyetv and Directv give SerialChannel 2.1 a try. It is available at www.coolDVR.com.

    Cocoa(R) Programming for Mac(R) OS X (3rd Edition)Cocoa(R) Programming for Mac(R) OS X (3rd Edition)

    Quartz Composer

    Recently I began writing an application for my toddler that uses compositions created with quartz composer.  I am very impressed with Quartz composer, this is an application that I was unsure of it value in Tiger.  QC makes it extremely easy to write and test 2d graphics, especially for kids educational software. QC still has a few short comings but it is progressing along nicely.   One of the things I had to work around was QC’s inability to play a sound file.  I recently completed writing a audio plugin renderer so that I can play a sound with my composition.  One fascinating thing about Qc is that it is possible to write entire games in QC.  I have run across asteroids and pong composed entirely in a QC composition.

    NSXML Event Parser vs NSXML Tree Parser

    This writing is along the lines of Soap services.  This is another question I see a lot floating around the net.  When is it best to use NSXML event parser or Apple’s newer NSXML Tree Based XML Parser?  The answer depends on the number of times you will need to get information from the xml document.  In other words, will the software require multiple queries of the file to get information or is all of the information in the file going to be presented to the user at one time.  The answer here is critical because the NSXML Tree parser can be very memory intensive as the entire XML is read into memory to form the tree to query.  The NSML Event parser does not load the file into memory it simply reads the file line by line and sends event notifications to a delegate so that something can be done with the information.  I learned this back when I created my TV listings app.  The Tree based parser was really slooooow.  Querying the XML document by Xpath or Xquery took a long time.  One thing I realized is that my app did not need to make multiple queries to the document.  It was much easier and much more memory efficient to use the Event parser to gather data and place into containers for later retrieval by the software.  What kind of difference did this make.  Well it went from 2 to 3 minutes to construct the data and present it to the user with NSXML Tree to 10 to 15 seconds with the event parser.  If anyone needs any help with this area please feel free to email me.

    Shortcut to Learning WebServicesCore

    If you are wanting some info on Web services and xml in cocoa have a look at Todd Ditchendorf’s blog.  He has been very very generous in open sourcing some terrific tools for just such a need.  

    Cocoa WebServicesCore

    Here is an old topic that I get a lot of emails about it.  About a year or so ago I wrote a cocoa app to get tv listings from SchedulesDirect (formally zap2it datadirect).  While writing this application I learned more about cocoa especially WebServices than I had expected.  For one thing WebServicesCore is very poorly documented and a bear to understand -it is almost as if someone gave up on the project and moved on to something else. WebServicesCore is not a pure cocoa solution it is a bit low level, core foundation (c based) implementation.  It uses CFNetwoks for authentication.  However, the service is fully functional and pretty robust once you get the hang of it.  When I say robust, I mean for my purpose.  My use of WebServiceCore was to access a soap service, send a soap envelope with a request, and download to a file.  The completed soap request simply put the file on the local machine so that my program could parse it for the tv listings.  The one positive thing about WebServicesCore is that it comes with a small program called WSMakeStubs which will generate code stubs to include in your cocoa project.  Simply point it to a WSDL file and it will create files in either core foundation or applescript. The following is a general rundown of what WebCoreServices does:

    1. Creates a soap request
    2. Invokes soap request
    3. Get HTTP authorization request
    4. Authenticate
    5. Invoke Soap request

    Here is a little tidbit of information about WebServicesCore.

    • Under Xcode 2.x the header files are located under the foundation framework.  However, in Xcode 3.0 it is now under the CoreServices frameworks.
    • For more information on WebServicesCore topic visit Todd Ditchendorf,s Blog.  I have never meet this person but this is an area he seems to be an expert.

    A different approach I learned a little later on that for a simple download request from a soap server I could use a pure cocoa implementation URL Loading System.  By using NSURL I could simply create a soap envelope with [NSString stringWithFormat] and send it along to get the file.  However a word of caution, this is not good for lets say a flickr web service or a similar sites.  It is just to slow. Works still the same for download request.  I find this method to be quite simple and fast for my purposes. A Brief rundown of Using NSURL

    • Get HTTP authentication challenge
    • Authenticate
    • send soap request

    For more information on using Cocoa’s URL loading system see the URL Loading System Programming Guide.
    There are other software options that provide code stubs for WebServies

    • gSOAP Has a nice GUI that produces C and C++ stubs
    • kernseife This is an Objc Framework primarily for iPhone development but can be used in other applications
    • If you need to interact with RESTful services try CocoaRest
      If anyone needs more information feel free to email me at tomhoh@mac.com