Pages

Wednesday 3 August 2011

iOS Coding 101 : Objective-C and the History

Hello world!

Need some help coding for the iOS? We will open an iOS, Java (Android), HTML, and JavaScript Coding 101 sections to help you out for your coding. We, personally, take coding as a brain squeezing time. Therefore, we would like to help out people for coding.

I will be helping you with the iOS coding using Objective-C. Alex Jeon will help you code Java, and Jeffrey will help you code both HTML and JavaScript.

Let's get started.
____________________________________________________________________________

What's the history behind Objective-C?

NeXT computers were using Objective-C making the NeXTSTEP OS. Brad Cox and Tom Love developed a language which is an strict superset of C, which was called Objective-C. NeXTSTEP was developed by NeXT computers and Sun Microsystems. However, Sun Microsystems lost interest and gave up. The Sun Microsystems went on and made Java, which was greatly influenced by Objective-C and very similar. NeXT computers were bought by Apple and influenced the birth of the Mac OS.

So, what's the basic of Objective-C?

When you make a Hello World programme, you will use a code like this:

#import <Foundation/Foundation.h>


int main (int argc, const char *argv[]){
      NSAutoReleasePool *pool = [[NSAutoReleasePool alloc]init];
      
      //insert code here...
      NSLog(@"Hello world!");
      [pool drain];
      return 0;
}


I will go over the code line by line.

Line 1: #import <Foundation/Foundation.h>
    This imports the code that is stored in the Foundation.h file. Developers that developed the language have made this statement to lessen the anger of typing the same code over and over.


Line 2:  int main (int argc, const char *argv[])
           This line of code is a function header or a line of code that starts a function. Main is a function that tells the computer to start with this function. The code in the brackets insist that the function doesn't take any arguments and instead of writing all this, we can just replace it with void. 


Line 3:  NSAutoReleasePool *pool = [[NSAutoReleasePool alloc]init];
            This line of code creates a pool of memory that we are going to use to run this programme. A part of NSObject called NSAutoReleasePool points (symbol : *) at the object pool which means instead of using NSAutoReleasePool, we can now use pool to insist that it is NSAutoReleasePool. Inside the braces, NSAutoReleasePool allocates (alloc) some memory for the programme. Then it initialises (init) the allocation.


Line 5: //insert code here...
             This is called commenting. You can comment and put notes to remind you of what you're doing here. However, when the computer complies this to run the programme, it ignores your comments and will not take it. For example, you are building a game that has HUGE amounts of methods that you want it to do. We can make HUGE amounts of comments so that it reminds you what it's doing. Commenting with two forward slashes (//) indicates a one line comment and you cannot press enter to keep on commenting unless it's a different comment. However, if you use forward slash and a star (/*) you can comment on as many lines you want but it will need a ending point which is star and a forward slash (*/) **.


Line 6: NSLog(@"Hello World");
            This line of code logs words to show up. This means that if you see the programme running, it will show you Hello World. NSLog is a part of NSObject. 


Line 7 : [pool drain];
             This line of code drains the pool of memory we have been using to run the programme. This means that we're giving back the amount of memory we have used to run the programme back to the computer. Since we pointed that pool can be used for NSAutoReleasePool, we can use pool instead. 


Line 8 : return 0;
             This line of code asks for an integer back of the value 0. If the value other than 0 was returned, it means there was some kind of error somewhere. Thus, if the value 0 is returned, it means your programme went well.


NOTICE:


1. Your statements are in curly braces ({ }). These statements tell your computer what to do.
2. Your statements end with a semi-colon (;). You must have these.


** Multiple line comment example: 
/*


asdfasdf


asdasd


*/



____________________________________________________________________________


To see some videos to get better understanding, go here:


Setting up Xcode : http://bit.ly/qaekYn
Explaining the Program : http://bit.ly/nxfUeG

[TheNewBoston is a YouTube teacher who teaches programming languages, etc.]

No comments:

Post a Comment