Cocoa for Scientists
By drewmccormack at Mon, Jan 8 2007 4:41am
Articles in this series include:
- Hello Brave New World
- Classy Cocoa
- Living Objects
- Good References
- It's All in the Genes
- Jekyll and Hyde
- Into Xcode
- IB, Therefore I am
- MVC is not the 'Motor Vehicle Commission'
- Popping Up All Over the Place
- The Value in Keys
- Observe and Learn
- In a Bind
- Beginning 3D Visualization
- Continuing 3D Visualization
- Finalizing 3D Visualization
- Representing Data in Tables
- Graphing Data with SM2DGraphView
- Telling Your Story with Narrative
- Python Scripters...Meet Cocoa
- Multi-threading Your App with NSOperation and NSOperationQueue
- Core Data Models
- iTunes-ifying Core Data Apps
- Core Animation First Steps
- Core Animation Layer Trees



Comments
Possible Cocoa for Scientists topic
Drew,
I find myself trying to reuse Obj-C classes and code, but I always run into the problem of how to do so cleanly. An example is, perhaps, writing a routine that has both code and IB resources such as a plotting library. Thus one would need (1) a graph view, with a frame and tic marks, presumably done in IB, (2) some routines for setting the graph properties, such as tic color or placement, presumably done in Xcode, and (3) some routines to plot data. All wrapped up in a nice reusable class, of course. I understand that a framework may be the cleanest way to do this, but the details of how to write and build a framework escape me despite a lot of reading. A graphing package is only one example of where a framework might be useful to a scientist. You use frameworks a lot in your examples, but might I suggest an installment or two on writing frameworks?
Thanks, Mark
Frameworks in Cocoa
Hi Mark,
Thanks for the suggestion. Code reuse is certainly an important topic.
Many people share small amounts of code these days simply as source files, and I actually find this the easiest way to incorporate third-party components. But if there are many source files, it may be worth building a framework. A framework is nothing more than a special target in Xcode.
In terms of designing frameworks, the main thing is to make as few assumptions as possible. Your code needs to work in a variety of settings, and with a variety of different classes. You need loose coupling, and you need to make sure there are 'hooks' in your code so that others can customize functionality. These hooks can include:
1. Methods that can be overridden in subclasses.
2. Notifications
3. Delegate methods
Writing a framework is generally more difficult that hacking together a piece of code that just needs to work well in one application. I think people sometimes underestimate how difficult it can be. For example, everyone seems to think Apple should have released an API for the iPhone by now, but to design that API to be flexible is not an easy task. Once you decide upon something in an API/framework, you can't go back easily in future. You have to make sure you cover as many bases as possible.
I'll think about how I could broaden this comment into an article in the series. Thanks for the feedback.
Drew
---------------------------
Drew McCormack
http://www.maccoremac.com
http://www.macanics.net
http://www.macresearch.org
Request
Hi Drew,
Thanks for all the tutorials. I enjoyed the tutorials with VTK.
I have a small request.
You know how programs like textmate and texshop compile tex in their apps.
How does this work? Does it include running command line commands in the app?
I was wondering if you knew and maybe could point me in the right direction. (if you have time)
Thanks again.
ken
NSTask
Hi Ken,
These apps will be running the external executable (command) as a subprocess. To do this, you can use the NSTask class.
I will try to write about this in a future tutorial, because it's something that is useful in scientific apps.
Drew
---------------------------
Drew McCormack
http://www.maccoremac.com
http://www.macanics.net
http://www.macresearch.org
ObjC vs. C++
This new registrant would like to add his sincere appreciation for the Cocoa tutorial and for MacResearch in general.
As a C++ (Carbon) developer, I procrastinated a *long* time before looking at ObjC because, IMHO, the loss of the STL and its derivatives (e.g., the Scythe Stat Lib) is very much a non-starter. Are you planning a chapter on combining ObjC and C++ for those out there like me? I suspect that there are some ;-)
Michael P. McLaughlin
Objective-C++
There is some documentation on combining Objective-C and C++ from Apple here.
Here is some sample code I was experimenting with that combines C++ and ObjC(it is not very clean, I will put up a cleaner version later). The code itself requires IT++, but it does show mixing C++ and ObjC.
Implementation file (.mm) here
Header file (.h) here
Regards,
Chinmoy