« Installing OmniFrameworks
// More Frameworks?
Frameworks package libraries of code and the resources needed by that code. By creating generic, reusable objects (classes) and packaging them in a framework, you can write code once and then use it in many different projects. The frameworks that comprise Cocoa - Foundation and Application Kit - demonstrate the power of reusable code packaged in frameworks.
In addition to the frameworks supplied by Apple, third party frameworks are also available to assist Cocoa developers. The Omni Group, creators of OmniWeb and many other excellent Cocoa applications, provides the OmniFrameworks.
Currently, 10 frameworks comprise the OmniFrameworks. They are OmniBase, OmniFoundation, OmniAppKit, OmniNetworking, OmniExpat, OmniTimer, OmniHTML, OmniFTPServer, OIF, and OWF. A description of each framework can be found here. These frameworks are free of charge and covered by the Omni Source License.
// Getting and Preparing to Build OmniFrameworks
The frameworks can be downloaded from Omni Group's ftp server. Grab all the compressed (.tar.gz) files in this directory: ftp.omnigroup.com/pub/software/Source/MacOSX/Frameworks. I suggest placing them all in a temporary directory in your home folder. Then uncompress the files using an app like OpenUp or from the command line.
The files we have just downloaded contain the source code of the frameworks. Before we can actually use the frameworks in our applications we must build the frameworks. To make this easier we will need to make a few temporary changes to the Project Builder preferences. Open Project Builder's preferences window. Select "Building" and then select "Seperate location for build products". Set the directory to "/Users/your_user_name/Build". Also select "Seperate location for intermediate build files" and enter "/Users/your_user_name/Build/Intermediates". These steps must be taken because some OmniFrameworks depend on other OmniFrameworks. Placing the build products in a common directory means that the frameworks we build first will be available when we build later frameworks which depend on frameworks already built.
Your Project Builder preferences should look something like this.
// Building OmniFrameworks
To build each framework you have to enter the directory you uncompressed, open the file framework_name.pbproj in Project Builder, and then click the hammer (build) icon in Project Builder. As stated above, some of the frameworks depend on other frameworks, which means you cannot just build the frameworks in any order you wish. I built the frameworks in the following order: OmniBase, OmniFoundation, OmniAppKit, OmniNetworking, OmniTimer, OmniExpat, OWF, OIF, OmniFTP Server, OmniHTML.
Although the build process is fairly straightforward, there are a few things you should know: If you get a message informing you of a SCM (Source Code Management) error then click the button to disable SCM for the project; it's not important. Also, if you get warnings telling you that assertions are enabled and you do not wish them to be enabled, then change the build style of the project from "Development" to "Deployment". Finally, OmniFTPServer and OmniHTML will not build "out of the box." You will have to set the paths to the External Frameworks which are used in the project to point to the frameworks you have already built.
// Installing OmniFrameworks
The frameworks you have built will be in "/Users/your_user_name/Build". Each framework has the extension ".framework". Copy all of these framework bundles into a standard location such as ~/Library/Frameworks/ or /Library/Frameworks. You may now want to edit the Project Builder prefs to eliminate the changes we made before building the frameworks.
One important note: if you use the OmniFrameworks in your app, you should not force users to install them. Instead, include the frameworks in your application's bundle. This will allow users to do a simple drag and drop install of your app and will ensure that the OmniFrameworks are available. The proper location in the application bundle for the frameworks is Contents/Frameworks. For more info see the "Application Packaging" chapter of Inside Mac OS X: System Overview.
// Using OmniFrameworks
Now the moment we've all been waiting for - we finally get to use these new frameworks in our Cocoa killer app! Create a Cocoa app in Project Builder (or open an existing project) and select "Add Frameworks" from the "Project" menu. Navigate to the directory where you placed the OmniFrameworks you built and select the frameworks you'd like to use in this project. Include the appropriate framework header file(s) in your code and then go to town. There's no documentation for the OmniFrameworks, but you should be able to find some interesting classes and functions by poking around the framework source code.
For example, try using the OFNumberOfProcessors() function contained in OmniFoundation: #import <OmniFoundation/OmniFoundation.h> and then enter the following snippet in one of your methods:
NSLog(@"This machine has %u processor(s).", OFNumberOfProcessors());
You should see the number of processors in your machine diplayed on the console.
There's a great deal of functionality in OmniFrameworks. Hopefully we'll bring you some additional tutuorials in the future, but until then have fun exploring OmniFrameworks!