GranitW
Lockergnome
Home

Archive for OS X development

Mac OS X 10.5.3; first beta released

Apple, on thursday, started seeding Mac OS X 10.5.3 to developers. So far, this update has about 75 bug fixes including critical memory leak with Core Animation. It seems the third update to Leopard will be coming in either April or May.

HowTo: Mac OS X’s Open Application Architecture Basics, Modify Safari

Mac OS X applications seem very solid and functional, but in fact an Application in OS X is just a basic folder with the “.app” extension on it. This type of file structure is called a bundle and it’s what Apple has been using not only for Application architecture, but for documents as well. Native iWork Documents, for instance, are folders that contain a compressed gz file, extra resources, and an informational property list.

So what does this mean? It simply means you can get into the contents of an Application or document very easily, just like opening a folder.

Below is a video showing how to open the contents of Safari.app and changing the Activity Window, and making the Activity Window the first item to open. You do need Apple’s Xcode tools to be installed to do any modify of Applications with ease(otherwise your going to have to use a text editor and edit the xml files by hand). This of course makes it so the MainMenu item wont open, so no menu will appear at the top of the screen. I did this by openning up the ActivityViewer.nib file. A NIB(NeXTSTEP interface Builder) file is an interface file, modern files now are called XIB(Xcode Interface Builder). I also modify Safari through a property list. A property list is very similar to a Hex code based system that holds certain properties to a file. The great thing about a property list though is that it is completely human readable. Even a non-programmer can understand it.

HowTo: Mac OS X Application Development Guide, Part 3

This is a series of guides about OS X Programming.

Who Should Read this:
This is a continuation of a guide that teaches people how to program in OS X. You can find the previous article here.

This tutorial is written for both beginners and experienced programmers alike. Much of it can probably be skipped by skilled developers. You should at least have good experience with Mac OS X. This part does include using OS X, finally.

For “already” programmers, this guide focuses on programmers that develop in C, C++, BASIC, Java, and other similar languages.

Organization:
I have split up the categories and concepts into grouped paragraphs to make it easier to skip or navigate through the article. An example of this is right below with the title of the group: “Get and Install Xcode“, in bold. I have also highlighted parts of the text like this: “example“, for beginner programmers that other developers can pass over. There is also something called “In Depth“, which explains more in detail of something. A new item in this guide are videos that can help you through the tutorial.

Much of this guide is overly in depth, and you can skip just about any part if you don’t want or need to learn anymore of a specific subject.

Get and Install Xcode:

Apple’s Xcode is the application, as well as the development suit, used to create OS X applications. You can get it from developer.apple.com for free, you do need an ADC account to access the downloads. The online ADC accounts are free. Be warned for people with low speed internet, Xcode is over a gigabyte, so it might take a while to download. If you have a copy of OS X Leopard, Xcode 3.0 is already on that disc ready for you to install it.

In Depth:
You do need to get Xcode 3.0, since this is the one I’ll be using for the tutorials. Version 3 is for Leopard and Tiger. You can still try to use Xcode 2 with this, but version 3 is dramatic different, some main applications have even been given a whole new interface. Also Version 3 brings in Objective-C 2.0, adding more features like properties.

When installing Xcode you can customize what you want installed. One that some might not want is the UNIX Environment tools. This just installs a duplicate of Xcode’s UNIX tools, like it’s compiler, into a different location so that the UNIX kernel of OS X can find it. This is useful only when you plan to install open sourced/ un-compiled software through the UNIX terminal.

Another item to look at is “Mac OS X 10.3.9 SDK”. Xcode 3.0 installs the 10.4 and 10.5 SDKs automatically, but leaves the 10.3 SDK as an optional install. Almost every major version of OS X are different from one another, so different that each version is considered it’s own platform. In Cocoa, multi-platform applications refer to programs that can work on multiple version of OS X.

Xcode:
After installing Xcode, go to your startup volume(Macintosh HD). In here you’ll find a folder named Developer. This is where Xcode has installed into, open this folder. Now you should see even more folders like: Applications, Documentation, Examples, Extras, headers, Library, etc… Open up the Applications folder in here. This is where all you developer tools and applications are held.

Two applications you should know about right now are Xcode and Interface Builder. Xcode is what developers use to create applications for OS X. There are a few 3rd party IDEs like REALBasic and Dimension. Before the intel transition, there was also Code Warrior for OS X, but at this point it has been discontinued.
Now, you can make Applications with 3rd party IDEs, but the problem is that they wont be as native or bug free(as possible) as an application made with Xcode. Xcode has been designed to build many different application environments and languages like the ones below:

Cocoa: OS X’s main Native environment. The languages you can use for it are Objective-C, *Java, Python, Ruby, Objective-C++, and Applescript.

*Note from Apple: Cocoa-Java is a learning environment for developers familiar with the Java language. It is not recommended for production work. The Cocoa-Java API is no longer maintained in parallel with the Objective-C API as the latter evolves.

Carbon: OS X’s secondary Native environment. The main languages used in this are C and C++. Originally carbon was created for people to easily port classic applications from MacOS 7,8,9 to Mac OS X. Today carbon is used to easily port C++ applications from windows and other platforms to the Mac platform. Examples of carbon applications are Adobe’s creative suite. The problem with carbon applications, especially in more modern version of the Mac OS like Mac OS X 10.5(Leopard), are bugs. Although not a bug, there are also bad GUI effects where the controls aren’t being composited correctly on the windows. One great feature of using Carbon is the ability to use some Cocoa APIs and features.

Java: This is a Nonnative environment using a virtual machine to run the application. It uses it’s own language, Java, but has some features and API of Cocoa rewritten for Java. This is normally only good if you plan to make multi-platform programs.

UNIX/BSD: this is *Darwin Native, with the ability to run on top of OS X with a GUI system like X11. Darwin can understand almost any language as long as you can find the right gcc compiler for the language. Here’s the languages Apple’s gcc compiler understands: C, C++, Python, Ruby, and others; You might need to download extra libraries for more support, like GNOME or KDE which don’t come shipped with OS X.

*Darwin is the operating system(kernel) underneath OS X and is based off of BSD, FreeBSD, netBSD, Mach, and a few others. Mac OS X itself is primarily a library of Frameworks and APIs. The user layer of OS X, is just made up of applications like Finder.app, Dock.app, and Spotlight.app. These applications are just like the ones you can make in Xcode, and many were made in Xcode. You can find these system applications in: Macintosh HD -> System ->Library -> CoreServices.

Now launch Xcode. The first thing that pops up is a menu with a few settings. Just use the default settings for now. Another window, is a splash screen with information about using Xcode, you can look at the information this window provides or just close it.

Building a Basic Browser:
In Xcode, go to the menu bar -> File -> New Project. This will bring up a wizard that will guide you through. The first thing to choose is the type of application and its environment you want. As you can see there is quite a list, but remember these are just the preset projects, not the limit it gives you.

Now we plan to make a native cocoa app, so scroll down the list till you find one called Cocoa Application. Select this, and then click the ok button. Next you need to give your project a name, and tell Xcode where it will be created. Name it something like Basic Browser.

Once your done, just click Next. Now your new project window will popup. On the left side of this window, a list of assets, from source files to frameworks, to the final Targets are located. Now go down the bottom of this list of assets to a Group called Nib Files. Open this by hitting the triangle and then double click the MainMenu.nib file. This will then open MainMenu.nib in Interface Builder.

Making the Interface:
Interface builder is the main place you’ll go to edit and create graphical interfaces for your applications. You can also develop interfaces in code if you’d want.

The first thing you should see is a window with the title: “MainMenu.nib”. This is where all the assets go for this particular interface. The items in here are:

File’s Owner: The Object that owns and controls the nib file

Application: The Object that represents the entire program

First Responder: This is part of something called the responder chain, which will be explained more in the next part of the guide.

Window (Window): The main window that will launch when you run the program. This is always created when you build a standard Cocoa application, but most programs don’t use this method and instead normally contain each window in it’s own nib file and not the main one.

MainMenu: This is the main menu bar of the application.

Now there might be another window open, if not go to the menu bar -> view.
This window is the library of pre-made objects. Many of these objects are called views, and are sub-classes of NSView. An NSView object is what is used to create visual interfaces like a button, or a text field.

Now go to the projects Assets window and open up the Window. You’ll see it’s pretty blank. Now go to the Library of Assets and go down main categories to something called Webkit. Go into this and you probably find one object called WebView. Drag this out onto the window, then resize it to fit the entire window.

Now go back to the library and go into the Cocoa category, now look for a group called NSToolbar. Drag out the NSToolbar object to the toolbar on the window. This will create a new toolbar for you. Now double click on it and it’ll open up, now delete all the pre-installed toolbar items that come with it.

Now go back to the library again and go into the Cocoa category and look for a view called an NSButton. Drag over 6 of these buttons to the toolbar. Now find a NSTextfield and drag it over. Now resize the buttons and window to your liking. then rename the buttons to:

“Back”
“Forward”
“Font +”
“Font -”
“Stop”
“Reload”

Now drag these buttons and the text field out onto the Window’s toolbar. Now close the toolbar’s customization sheet window by clicking ok. Then go up to the menu bar -> View -> Show Inspector or do the short cut: shift-command-I.

This is the window you use to edit attributes about an object. Now make sure the Toolbar is selected and go into over to the Inspector Window. Check to see if the first tab is open and change it so only the views are shown, without the text underneath them in the toolbar.

Here’s a video of the above steps(Click on Image):

Now select the WebView object and go to the size tab in the Inspector window. In the Autosizing part, click on the faded arrows which appear in a black outlined square. This makes the WebView stretch as the window stretches.

Connecting Actions:
An action is one of the ways that objects interact with each other through user input. Every time you click a button your sending an action for instance.

Many objects in Interface builder come with pre-made actions,and we’re going to take advantage of this. Double click the Toolbar in the Window object to open up the customize sheet window. Now right click or control-left click the button with the titles, Back. Drag the cursor to the WebView. As you do this, you’ll notice a bluish line, when the WebView highlights(when you’re over it with the cursor, let go of the mouse button. A black HUD window should appear. This window lists actions that the WebView contains. Find the goBack: action and click it. Now do the same thing with the rest of the objects in the toolbar as shown below:

Back = goBack:
Forward = goForward:
Reload = reload:
Stop = stopLoading:
Text+ = makeTextLarger:
Text- = makeTextSmaller:
The Text field = takeStringURLFrom:

Now simulate the interface by going to the menu bar -> File -> Simulate Interface. The first thing to happen is the browser Window opening. in the textbox type in a url. Remember this is a strict system that needs the user to type in the full address, so type in an address like this: “http://www.google.com/”. After, hit the return key. That’s it with the interface it works. Now go back to Xcode and at the top of the Project Window, click Build and Go.

What did you notice? Did you realize it didn’t work, is your app just bouncing infinitely in the dock? . Yep, even in Cocoa, it’s not that easy to make something as complex as a browser that easily. Actually there is one last step needed. You need to link the webkit framework to your project.

So now, go back to Xcode and go up to the menu bar -> Run -> Stop. This will terminate your application. In the project Window, go over to the left side and scroll to the group of assets called Frameworks. Open this, then right click or control-left click the group called Linked Frameworks. In the contextual menu go to Add -> Existing Frameworks… Now it will pop up a modal window with the frameworks folder. Go down to the bottom, and you’ll find Webkit, at about the second last item. Now add it. Xcode will prompt you with a sheet window, but simple hit Add again.

Now once again click Build and Go. It should work, and now you have a fully functional, yet basic web browser.

There’s yet another video:

Extra Information:
With your new program running in the Dock. Click it’s icon in the Dock, while holding down the command key. This will open up its parent folder in the finder, showing you where it’s located. Now right click the Application in this new Finder window, then click Show Contents. A new window will pop up, go into the folder Contents, then Resources, and again in English.lproj. You’ll find the interface you made. OS X applications rarely compile the nib files. This means that you can click on this nib and edit your interface with Interface Builder, even though your app is already compiled.

HowTo: Mac OS X Application Development Guide, Part 2

This is a series of guides about OS X Programming.

Who Should Read this:
This is a continuation of a guide that teaches people how to program in OS X. You can find the previous article here.

This tutorial is written for both beginners and experienced programmers alike. Much of it can probably be skipped by skilled developers. You should at least have good experience with Mac OS X. This part does not include using OS X yet, and more focuses on the background of OS X programming and the Objective-C language.

For “already” programmers, this guide focuses on programmers that develop in C, C++, BASIC, Java, and other similar languages.

Organization:
I have split up the categories and concepts into grouped paragraphs to make it easier to skip or navigate through the article. An example of this is right below with the title of the group: “Basics of C“, in bold. I have also highlighted parts of the text like this: “example“, for beginner programmers that other developers can pass over. There is also something called “In Depth“, which explains more in detail of something.

Basics of C:
C is the most widely used language in the computer world. Almost every language whether C++, Objective-C, or Java, your using the concepts and ideas created by C.

In Depth:
In the 60s, AT&T Bell labs was developing an operating system called Unics, they created a language to write it in called B. In the late 60s to early 70s, the programmers wanted to make the OS more portable, B was to integrated with the hardware to allow this. They need to develope a new Languages, this is what started the development of C. A few years later, AT&T Bell labs finished their OS in C renaming it UNIX. C is a very portable system that can rest on almost any hardware setup making it very popular. C was also very easy to use compared to other languages.

To start off with with basics of C, you need to understand the “#include” keyword. This is a needed asset which imports and connects outside resources to your code. The most imported resources would be from the standard library for the language along with other resources to your code. In Objective-C, you’ll normally be adding something called Cocoa.h to each document in your project.

If you’ve used another language like BASIC, this concept might be new. In BASIC, the library/compiler is normally proprietary and built into the IDE(Integrated Development Environment) application. In C and languages based off of it, the compiler is noramlly not a part of the IDE, this means it needs more information on what to do and what code to use. Also, compilers like this are more open and extensible. This can help expand developers’ applications by giving them the ability to use 3rd party frameworks and systems. This is one of the big reason for the include keyword. Besides making the applications more feature rich by allowing outside sources to connect to it, it can also make your code more organized and make your programs smaller.

In an environment like Realbasic, for instance, a application is given a dylib(Dynamic Library). This dylib contains all the functions and resources built into Realbasic, not just the ones you’ve used. This can add up to large file sizes. In C and other languages, the include keyword is not just needed to import the standard set of libraries, but to import only the ones you want, making your applications small.
Another great feature about the #include, is that it allows you to split up your code into multiple files. This allows more people to work on the same project, and it makes it easier to go over a specific asset. Here’s an example line for including a source file, which normally is a header file.

#include <stdio.h>

The first part is “#include”, which tells the preprocessor(a system before the compiler) to include a source file. The next part is “<stdio.h>”. The “<” and “>” tags mean that you want to get the source file from a standard system folder, normally one containing files from the standard set of the Language. The “stdio.h” is the source file your looking for. Now this code is not for the actual compiler. This line is for something called the preprocessor. All keywords with the “#” in front of them are for the preprocessor, which gets the code polished up and ready for the compiler.

Lastly with the #include keyword, to access normal source files you’ve made, you should use quotes instead of tags like this:

#include “foo.h”

This means that it will look in the same folder as your code, for the file foo.h.

The next part to know about C are the variables. Variables are an incredibly valuable resource in programming. a variable like explained in the last part is a space that holds data. Here is an example of declaring or making a C variable, with a BASIC version of the code underneath:

int foo;
Dim foo As Integer

alternative:

int foo = 100;
dim foo As Integer = 100

alternative:

int foo, foo2;
dim foo, foo2 As integer

The next important part to learn about before getting into Objective-C, is the conditional statements. A conditional really helps make a program non-linear and more feature rich. Just about every program out in the modern world uses many of these conditional statements. Here’s an english readable version of one:

If a person presses the computer’s power button, then the computer will turn on.

Now above, a computer won’t understand what that means. We have to translate it into a more simplistic form like this:

if(person.presses == computer.powerButtonPressed) {
computer.turnOn;
}

Above, I wrote out the same sentence in C. At this point ignore the parentheses and curly brackets. The first part is “if” which is a keyword that starts the conditional statement. The next part is “person.presses”. I made the person into an object, and presses into a method. The method returns a boolean(true or false) value. Next I added a “==” which means I want to see if the right side of the statement equals the left. After that, I add “computer.powerButtonPressed”, in which computer is an object and powerButtonPressed is a method returning a boolean value. “Computer.turnOn” is the results of the conditional statement.

For beginners you might want to look over the last paragraph a few times before continuing.

Now about those brackets and parentheses. In a language like C, these are normally used as containers. These containers hold code with in them, away from the global code. A real world example would be: in a house, a refrigerator is a container that holds food. Now in the conditional statement above, the parentheses are used as a container that hold the statement. The curly brackets are used as a container that holds the results.

In C, “=” and “==” are to different operators. “=” means you want a variable or another asset on the left side to contain the value of the asset on the right side. The “==” means you want to know if the value on the left equals the value on the right:

int var1;
var1 = 5;
this makes var1 have the value 5.

if(var1 == 5){
do.this;
}
this checks to see if var1 does equal 5.

Objects and Classes:
The Language C, is not an object oriented language. It is a procedure language, which means it uses steps to reach it’s desired output or state. In Object oriented languages like Objective-C you use objects and methods to create a network or structure that forms your application. Another concept you need to learn about are classes. When you create your own custom object, your making what is known as a class. A class holds the information needed to create the objects and is more like the factory than the product(in a sense).

A class tells the compiler what the object is and what methods and other assets it has. When you build a class in some languages it looks like this:

function Class1{
this.method1 = function{alert(“hello world”);};
this.var1;
}

Above is an example of a class from Javascript. In many languages there is something called a function. A function separates code like a container from the global code, it’s useful because the container can be called from anywhere. This can save you from writing down the same code more than once since it’s already in the function. Many languages were created before or away from the idea of the object oriented concept. To adapt, many languages just expanded on the functions to create class interfaces. To make the above function class into an actually object also called an instance of the class, you do this:

var object1 = new Class1;

In Objective-C, normally a class takes up two files, the header file and what is called the implementation file. I’ll get into those later. here’s how to create an Objective-C object:

NSImage * image1 = [[NSImage alloc] init];

Understand Some Objective-C Concepts:
In Depth:
Objective-C is based off of C, but more specifically it’s an extension to Ansi C. “Ansi”, just means that the C code used is the standard set by the American National Standards Institute(ANSI). To be even more specific, Objective-C is based off of a language created at Xerox PARC known as Smalltalk.

Smalltalk, released in 1980, was the first language called object oriented. Smalltalk and Objective-C are what is considered pure object oriented. Unlike C++ or Java, in a pure OOP primitive values(integers,characters,etc) are the same as object values. To add to this, in a pure OOP, primitives like integers are objects themselves. Like for instance, in C++ you’d use a variable like int, in Objective-C you’d use NSInteger. NSInteger isn’t just a variable, it’s an object.

In C, like above, you have the include keyword, written as “#include”. This resource happens to be in Objective-C as well, since Objective-C is on top of C. Now to tell you the truth, you should never use #include in your Objective-C programming. Apple, replaced this concept with something called #import. This has the same properties as include and works almost the same way. The only difference with the import keyword compared to the include, is that it tells the preprocessor to check to see if the code it’s trying to import has already been imported. If you use “#include”, it wont care if it already imported the code, it’ll do it again making your apps bigger than they need to be by having 2 or more of the same exact thing. here’s an Example:

#include <Cocoa/Cocoa.h>

#import <Cocoa/Cocoa.h>

If you plan to use ObjC to make applications in OS X your going to have more than one source file in your program. Each one of these files connects to the Cocoa.h header file. If you use #include you will be compiling Cocoa.h in your application multiple times. This can lead to a large file size, and even a long compiling time.

Objective-C or ObjC uses a different means of building objects and accessing methods and variables than most languages including C. You can however use C functions and methods with ObjC with no problem, like this:

NSLog(@”this is an Objective-C String”);

NSLog although looks like an ObjC function of some sort, is actually C. The part in the parentheses is ObjC. The “@” tells the compiler that this happens to be an ObjC String Object also called an NSString.

Like I said in the previous part of the guide, ObjC uses what’s called messages to communicate to objects. Here’s two simple example:

[Object method:argument];

[Object method:[Class method]];

The first might be easy to understand. You first have the Object which you want to talk to, then you have the method. The last part is the arguments that the message is sending to the object’s method.

The example under the first one, might look a little harder. It’s exactly the same until you reach the argument part. What you have is “[Class message]”,
which is a simple and common way to get an action done by a method of a class with out making the class an object. I could have done this:

Class * Object2 = [[Class alloc] init]; //I’ll get into “alloc” and “init” later

[Object message:[Object2 message]];

above is the same as:

[Object message:[Class message]];

The great power of ObjC is the ability to use a class with out creating an instance of it. For example, to load an image to be used by an item in the tool bar, you would do this:

[tbOpenFile setImage:[NSImage ImageNamed:@”OpenFile.png”]];

This is a real world message used in many programs to add a graphical image to a tool bar item. The first part is “tbOpenFile”, this is the tool bar item you are accessing. The next part is the method: “setImage”, this will set the image. After that you add to the setImage argument: “[NSImage ImageNamed:@”OpenFile.png”]”, which is a sub message inside a parent message. This sub message uses a class called NSImage and it’s method, ImageNamed, to locate the file OpenFile.png in the Resources folder. In all OS X applications, there is a folder called Resources which holds all the assets for the program.

Next Part:
Finally, we’ll get into the IDE called Xcode, provided by Apple. I’ll show you how to build a basic web browser for the Cocoa application environment; it’s easier than you might think.

HowTo: Mac OS X Application Development Guide, Part 1

This is a series of guides about OS X Programming using Xcode.

Who Should Read This:
This tutorial is written for both beginners and experienced programmers alike. Much of it can probably be skipped by skilled developers. You should at least have good experience with Mac OS X. This first part does not include using OS X yet, and more focuses on the background of OS X programming and the Objective-C language.

For “already” programmers, this guide focuses on people that develop in C, C++, BASIC, Java, and other similar languages.

Organization:
I have split up the categories and concepts into grouped paragraphs to make it easier to skip or navigate through the article. An example of this is right below with the title of the group: “Objective-C and Cocoa“, in bold. I have also highlighted parts of the text with a blue color like this: “example“, for beginning programmers that other developers can pass over. There is also something called “In Depth“, which explains more in detail of something. I have also styled the code examples so they’re easier to read.

Objective-C and Cocoa, a Little Background:
If your a developer who is use to C, C++, Java, and other forms of programming like this then learning how to develop software in OS X might actually seem harder to you than to a novice who’s never programmed before. The reason; OS X uses something know as Objective-C. Objective-C or simply objC, is the primary language for writing OS X applications. It has to be the most odd balled language I have ever used. Now saying that, I don’t mean it’s bad. On the contrary, ObjC is about the most powerful and versatile language I’ve ever used and to a novice it is also the easiest excluding BASIC.

What I’ve realize with ObjC, is that you have to forget the concepts of programming that your use to. It’s not that ObjC by itself is hard to understand, but when mixed with OS X’s primary application environment known as Cocoa it can be.
An application environment in basic terms is the set of frameworks, libraries, programming languages, and other tidbits that build up and run an Application. Sometimes it’s said as “application development environment”, which more specifies to the tools used to make the application.

The new version of OS X(Leopard) has 4 main application environments: Carbon, Cocoa, Java, and BSD. If your using OS X Tiger or lower, then the main application environments you have are: Classic, Carbon, Cocoa, and Java.

This series of tutorials is based around the Cocoa environment. If you would like to program in C++, you should look at Carbon. Carbon was the universal application environment between MacOS 9 and Mac OS X, it has now become an alternative to Cocoa for C++ programmers. Carbon does not contain many of the great features and tools as Cocoa however and your Applications wont fully feel or look like OS X programs. If you are an experienced C++ user, but would like to use Cocoa, you should look into Objective-C++ which I’ll explain in a later part of this guide.

In Depth:
Cocoa was originally created by the company NeXT. At the time, Cocoa was called NeXTStep. If you read my article here, it’ll explain how NeXTStep became OS X. Well NeXTStep was more than an OS, it was also the name of the application environment. Eventually NeXT threw out the OS(the Mach Kernel) and with help from Sun Microsystems, evolved the Application environment into OPENStep. OPENStep was a multi-platform environment that became a competitor to Java. Eventually Apple bought the company NeXT over BeOS, to use it’s OPENStep system as there next evolutionary operating system. Apple then changed the name OPENStep to Yellowbox and there new OS based on OPENStep was called Rhapsody. Yellowbox up until developer release 3 was built to run on Macs, as well as on top of Windows, Linux, UNIX, and Solaris. Do to low developer support, Apple canceled the multi-platform model and instead focused on Rhapsody for Macs. Eventually in 1999 Apple release Rhapsody to the public as Mac OS X Server 1.0. In 2001, Mac OS X 10.0 was released. It took until Mac OS X 10.2 for Apple to finish the x86 version of OS X in 2002, which was never released until 2006 with Tiger. If you still want to use a Cocoa like environment with the Objective-C language to build multi-platform software, look into GNUStep. GNUStep is very much like OPENStep, but is much older and still has an active community.

Along with the NeXTStep environment, NeXT needed a language that was dynamic and powerful. In the end they created an object oriented language called Objective-C. Objective-C in NeXTStep was only two basic frameworks: Application Kit and the Foundation framework. Today, OS X contains over 80 built-in frameworks. This allows more powerful applications and features, but it also makes it harder when you first start learning about Cocoa.

There are some pieces of NeXTStep still in Objective-C and Cocoa. Like for instance, the built in objects have the Prefix “NS”, this stands for NeXTStep. The interface files, that you’ll learn about later have the file extension “NIB”, which stands for NeXTStep Interface Builder. In Mac OS X 10.5 Leopard, Apple has started to faze out these connections. The new NIB format now can have the extension “XIB”, which means Xcode Interface Builder. Xcode is the name of Apple’s development application as well as the rest of the suite that comes with it. Like with Mac OS X, there is only one version of Xcode, and it’s free from Apple here.

Object Oriented(OO) Languages:
An object oriented language or OO is a high-end or high level language. This doesn’t necessarily mean it’s hard, on the contrary this means it’s easier. The higher the level, the more human readable and understandable it becomes. OO languages are about the easiest to learn.

In Depth:
Back in the day people use to program from binary. Binary is the lowest language there is and it is not considered a programming language. Binary is actually a computer language. A computer language is a language that the computer natively understands but a programmer might not. To make it easier to program, new languages that were more human readable were developed. These languages would then translated or compiled into binary for the computer to understand.

Today the languages that replaced the need to program in binary have as well been replaced by languages that are either based from them, or on top of them. This bring in the concept of levels. Binary is at the lowest level, and something like Objective-C is up in a much higher level on top of something known as C.

The most used language in programing is C. Even if you haven’t used C, you might have programmed with a language on top of or based off of C. In the next part of the guide, I’ll explain more about the C language.

Objective-C is a language based off of and on top of C. This means that you can use the C language along with Objective-C. for example:

If(str1==@”hello”) this is C using ObjectiveC variables
{
[str1 setString:@”Hi”]; This is ObjectiveC
}

Another language, C++, is based off of C as well. You can’t directly integrate C++ and Objective-C together, but they can work together indirectly. This indirect way of using C++ and Objective-C together is called Objective-C++. I will get into this more later.

OO languages use a concept in which there or these things called objects. To make it relative to the real world, you can picture an object as a physical item like a house or table. I’ll use “car” as an example Object. A car has assets that contain functions, a few are: a steering wheel, a acceleration peddle, and a brake peddle. These assets, in an object oriented language are called methods and are used to create an action of some sort. A Steering wheel for example creates the action of turning the car left or right. In OO you would create this action through a command or sentence like this:

car.steeringWheel 45

Above is an example written in the BASIC language. First I wrote down the object that will be accessed, then I add a dot. The dot explains that you want to access something in the object. Then I added on the asset, steeringWheel. In OO these assets are called methods. In most object oriented languages you are not allowed to add spaces in side the method’s name. The last part is called an argument. An argument is what you want to tell the method and in turn it tells the object what to do. In the example I tell the object 45. 45 means that that I want the car to rotate 45 degrees to the right. If I said -45, it would rotate 45 degrees to the left. Now for beginners that might be wondering if this object is real, it’s not this is just an example object I just made up out of thin air. Car doesn’t exist in the main language of BASIC.

A great power of OO is the power of hierarchy. Besides Functional assets(methods) like a steering wheel, you can have objects in side objects. So let’s say, to make it easier for programmers to understand how to turn the car object, let’s make the steering wheel an object which has 2 methods. The methods are left and right. Here’s what it would look like:

car.steeringWheel.right 45

Now let’s say that you want to record this rotation value. Then you need to add a property or variable to the object. a property/variable(differently named depending on the language and usage) is like a container that holds information or data. Let’s say there is a Gauge of some sort on the car’s dashboard that shows how much the car’s steering wheel has rotated. We’ll call this swRotateGauge, the “sw” stands for steering wheel. here’s the example again:

car.steeringWheel.right 45
car.swRotationGauge = 45

We just added to the swRotationGauge container, the number 45.
Now most methods and objects will do more than one thing. A normal object in the BASIC language would probably add the two commands above in one like this:

car.steeringWheel.right 45

The above method would rotation the car and add the number 45 to the swRotationGauge on one line. Car is the main object, steeringWheel is the subObject, and right is the method. Again, 45 repersents the argument the programmer gives to the method right.

A Little Bit of ObjC Code:
In this example you’ll see the same action, written in 3 different languages. There will be an object called car. Car has a method called steeringWheel with 2 arguments that turn the car. Read the first two actions, one written in BASIC, the other in C++. See if you can identify what both the arguments mean. Then look at the Objective-C example.

BASIC:
car.steeringWheel 50,10

C++:
car.steeringWheel(50,10);

Objective-C:
[car steeringWheelRotates:50 Speed:10];

In the first example, we are rotating the steering wheel 50 degrees with the object, car, at the speed of 10. The big problem with BASIC, is not knowing anything about the arguments on paper. If you don’t know the arguments you have to look in the reference. Also when someone reads your code, with out knowing the argument names of a method, they might not understand what the code is doing.

In C++, you have the same problem as BASIC, you don’t see the names of the arguments. However, it is strict with the semicolon, which can help advance users organize code better.

When you went down to the third example, you might have been confused. The Objective-C example might not make any sense, or it might have made the most sense. First off you might notice the brackets “[” and “]”. These surround what is called a message. ” [car steeringWheelRotates:50 Speed:10];” is a message. You are sending a message to the object car to rotate the steeringWheel, which in turn turns the car. So now what do you think the method itself is? well this is the method:

steeringWheelRotates:Speed:

In Objective-C, the Methods are split into sections, each section is separated by a colon(”:”), and each section represents an argument. steeringWheelRotates:Speed: is the full method name and the two arguments are steeringWheelRotates: and Speed:. The colons are apart of the name. To compete the arguments, you add the values: positionLeft:50 and Right:50.

Some methods in Objective-C don’t have arguments, if they don’t you just write the name with out any colons like this:

[car turnOn];

BASIC:
car.turnOn

C++:
car.turnOn();

Next Part:
In the next part of the guide, I will explain about the C language(for beginners) and how Objective-C adds to it.

1 2 3 ... 999999