iOS 6 Basic Objective-C Course - part 1
A couple of years ago I want it to learn how to make iOS apps and I had a very hard time finding resources and tutorials to get the basics of Objective-C. I know it is still challenging but as a developer I feel I love this more and more every day.
Right now, almost every web design or domain registrar company offers mobile websites for a cheap price, but the real truth is those mobile sites are just designed for stores retails where only have one business model to go. Developers can help you get your idea running and follow up in several stages to even scalate the app to not just show images but make your app stand up by letting their audience do the: Create-Read-Update-Delete functions which gives you more freedom at the time in the long run.
Well, enough talking and start working! We are going to start with some basics of Objective-C. I assume you have some programming experience with variables, loops and debugging in other languages.
This Objective-C course has 3 parts. So check back in a couple of days for part-2.
Requisite: You should have an Apple developer account, Xcode 4.5 and iOS 6 to follow along.
Step1: Start up Xcode, create a new project.
Step2: Choose the Command Line tool by selecting Mac OS X>Application>Command Line Tool.
Step3: Enter “Basic OBj-C Course” for the Product Name. Keep the file type to: Foundation. Save the project to your iOS 6 projects folder.
Step4: On the left side of the Xcode window there is a main.m is file. We are going to work on it, so click it to open it.
You should see the following code:
// BasicObjc
//
// Created by D on 11/20/12.
// Copyright (c) 2012 sdbwebsolutions. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
}
return 0;
}
We're going to build our first App: Hello world
Press the Run button in the upper lefthand corner. By clicking Run you are actually telling Xcode to build (compile all files into a single program) and run the program. You should see the following output in the lower part of the screen: This is the console log.
The first (//) statements are just comments.
The next statement, means “go grab Foundation/Foundation.h, because it has some stuff we need for the program.”
The next section, called the main function, is the heart of the program. It is all contained within brackets {}. It's where you execute whatever you want your program to do.
{
}
Everything within the brackets {} is called a block statement. Every statement within a block statement requires a semicolon ";" at the end.
The first line allows our program to use or let's say borrow memory from the computer for our application.
Then it comes our first function: NSLog()
NSLog() is a function that displays in the console log everything between the first and second double quotation marks. In this case it prints out a string or list of characters.
Note the quotation marks has a little @ sign before the quotation marks. You need to put this whenever you use a string in Objective-C, otherwise, at least it will give you an error.
After NSLog, our program has completed its purpose. However, we have borrowed memory in an autorelease pool, and everything that required memory is now finished. Since we're now using ARC, the computer is instructed to drain the “pool” of memory so that the device can use the memory elsewhere. YOu don't have to explicitly "release" memory anymore.
The final line it's the last piece of code
terminates the main function by requiring the console to return the value 0, if everything was successful.
Okay, This is the end...of part-1. See you next time, thanks for sticking out all this time!
continue to part-2