WHAT YOU NEED
To make iPhone and iPod Touch games/apps you need to have an apple computer, a iphone developer's license, the iPhone SDK (software development kit), and the knowledge of Programming in Objective-C. When I say apple computer, I mean a real Macintosh. I don't think just having Mac OS X on a Windows computer will work. An iPhone developer's license is $99 a year and you don't NEED that until you want to put your app on to the App Store. The iPhone SDK includes all the tools necessary for making iPhone and iPod apps. Finally, I said you needed knowledge of Programming in Objective-C. Unless you hire a programmer to program for you, you have to know Objective-C, which is what you are going to learn, if you continue reading...
CLASSES, OBJECTS, and METHODS
First concept you should know in Objective-C is that it is an object oriented programming language. Object Oriented programming is a programming paradigm that uses "objects." First off I am going to give definitions (very simple ones):
Object- a thing, commonly referred to as an instance
Method- actions that are performed on the object/instance
Class- where object/instances comes from
OK, I will give you an example so you can easily understand this. Lets say you own a computer. You have a specific computer; one no one else has (an object obviously cant be two places at once). Your specific computer is an instance of a computer. You do certain things to your computer, certain actions, like going on the internet, using email, playing games, or watching movies. Theses actions would be referred to as methods. So in this example the class would be called Computer, your instance would be your specific computer (lets name it myComputer), and the methods for this class would be:
-(void) goInternet;
-(void) useEmail;
-(void) playGame;
-(void) watchMovie;
Notice how I wrote them. That is the way you define your methods. First there is either going to be a plus or minus sign which means if it is a class method or instance method. Next there is the return type (in this case all void). Then there is the method name that you make (you can come up with, usually written in camel case form as I did).
XCODE: Xcode is the programming environment application you use to actually insert and edit code. When you create a new project there will be 2 separate files. One called @interface and the other @implementation. The @interface file (.h) is where you describe the class, and you define the methods and instance variables. The @implementation file (.m) is where you put in the actual code that implements your defined methods. This is how an interface file would look like:
@interface NewClassName: ParentClassName
{
//All your Instance Variable Declarations Go here!
}
methodDeclarations
@end
This is how an implementation file would look like:
@implementation NewClassName;
//All your method definitions Go Here!
@end
Instance variables make up your class. So say you had a class named Computer. Say that the Computer class has the instance variables name, age, size. Every Computer object you made would be made out of a name, age, and size. This is how you would declare (define) those variables:
int name;
int age;
int size;
The int part is the data type which will be discussed in the next section.
OK, the last thing I want to include in this section is show you the specific syntax used for applying methods to your Classes or instances: [classOrInstanceName method];
An example of a class method that would go with the above examples is:
myComputer = [Computer new];
The method new is a factory or class method. It is being applied to the Computer class. This method would return data and store it in the object myComputer.
DATA TYPES
Includes int, float, double, char, and more!
int- most basic data type, a variable declared as int can hold integral values
float- variable declared as float can be used to store values that has decimal values
double- similar to float, variable declared as double can store about twice as many digits as float
char- stores single character
id- variable declared as id can store any object of any type, this variable is important for some more advanced concepts like polymorphism and dynamic binding which is used a lot
LOOPING AND DECISIONS
The majority of the time when you are programming in Objective-C you use logic. You will most likely have to go through loops and have your program make decisions based on certain things.
A very popular decision making statement is th if-statement. The syntax goes like this:
if(boolean expression) {
//Code in here gets implemented if boolean is true
}
You can also do this which is called the if else statement:
if(boolean expression) {
//Code in here gets implemented if boolean is true
}else{
//Code in here gets implemented if boolean is false
}
Next is looping with the for statement. Here is an example:
int i= 0;
for(i = 0; i < 100; i++){
//Code here
}
So the code will be run, i will be incremented, i will be checked to see if it is less than 100 and if so the loop will continue. One way to stop a loop is to use a break; statement.
OK, one other loop to use is the while loop. The basic syntax for the while loop is:
while(condition){
//Code
}
This is almost like the if statement but it keeps running the code in the brackets until the condition is false.
INHERITANCE
This is a fairly easy concept to understand. Remember all the way up in the Classes, Objects, and Methods section on this page? I showed how the interface file looked like. In there it says ParentClassName. When you have a Parent class(the class that is at the top of all the other classes in a big hierarchy is NSObject, so you always get the methods of that class) you get all the methods and variables of that parent and you can automatically have them without having to rewrite them. The child of the parent class is also known as the subclass. The process of subclassing is very popular. When you want to subclass, you pick an existing class and put it into the place of the ParentClassName spot.
