iOS Hackathon 2012 Objective-C talk
Upcoming SlideShare
Loading in...5
×
 

iOS Hackathon 2012 Objective-C talk

on

  • 762 views

A primer on Objective-C and iPhone programming presented during December 2012 iOS Dev Scout Hackathon

A primer on Objective-C and iPhone programming presented during December 2012 iOS Dev Scout Hackathon

Statistics

Views

Total Views
762
Views on SlideShare
762
Embed Views
0

Actions

Likes
0
Downloads
8
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

iOS Hackathon 2012 Objective-C talk iOS Hackathon 2012 Objective-C talk Presentation Transcript

  • OBJECTIVE-C AND YOU First step on your Journey to writing iOS appsMonday, January 14, 13
  • ABOUT • Started Programming since 14 years old. iPhone development for 2+ years • Runs software development company Getting Real - Clients include Prestige Magazine, Google Earth Hour etc.. • Does iOS Corporate Training - Clients include OCBC, Imerys, Barclays bank, IDA etc.. • Decided to go into mobile development because smartphones have changed and will continue to change the worldMonday, January 14, 13
  • WHY LEARN APP DEVELOPMENT? • As of Jan 2013 - Apple has paid out of USD $7 billion to developers • Apple now has over 200 million iTunes accounts - the largest credit card hub on the internet. Earning money online has never been easierMonday, January 14, 13
  • PREREQUISITES • An Intel-based Mac • Xcode IDEMonday, January 14, 13
  • OBJECTIVE-C BASICS And a random motorcycle.Monday, January 14, 13
  • WHAT IS OBJECTIVE-C? •A general purpose, high-level, object-oriented programming language that is a wrapper over C programming language • The main programming language used by Apple for iOS programmingMonday, January 14, 13
  • WHY OBJECTIVE-C? • Use Objective-C if you don’t want your app to suck. Seriously.Monday, January 14, 13
  • OBJECT ORIENTATION • Using objects as ‘data models’ •A way to think about programmingMonday, January 14, 13
  • VOCABULARY • Class - The generic “type” of an object. e.g. Smartphones • Instance - A specific object of a given class. e.g. iPhone 5 • Method - A function that an object performs. e.g. Make call, send message, surf for cat pictures on 9GAG • Variable - A quantity or value. e.g. Percentage of battery life, number of messages in inbox.Monday, January 14, 13
  • MORE VOCABULARY • Class - Car • Instance - BMW Z4 • Methods - Drive, convert roof, attract women • Variables - Amount of fuel, speed (km/h)Monday, January 14, 13
  • DATA TYPES Name Explanation Example void Nothing - int Integer or number 1, 2, 3 float Decimal-point 3.14562 BOOL Yes or No YES, NO NSString Sentence/ Word @”Hello World” id Anything -Monday, January 14, 13
  • DECLARING DATA TYPES int cupsOfCoffee; int amountOfWork float productivityLevel; cupsOfCoffee = 3; productivityLevel = cupsOfCoffee * amountOfWork;Monday, January 14, 13
  • DEFINING VARAIBLES Class *objectName; - NSString *mySentence; What is the * ? Not for C types like int, float, BOOLMonday, January 14, 13
  • METHODS •A function that an object can perform • Can return a value, or not • e.g. the BMW class will have a getPrice method - (int)getPrice:(Car *)typeOfCar { // Input code here return carPrice; }Monday, January 14, 13
  • METHODS • Use Parameters / Arguments to pass more information to methods • Example: squareNumber - (int) squareMe: (int)x { return x * x; } [self squareMe:20];Monday, January 14, 13
  • METHODS • Methods with more than one parameter/ argument • Example: multiplyNumbers - (int) multiplyNumbers: (int)x andSecondNumber: (int)y{ return x * y; } int numProduct = [self multiplyNumbers:10 andSecondNumber:50];Monday, January 14, 13
  • METHODS • Invoking Methods on Objects [object method]; [object methodWithArgument:argument]; int variable = [object methodWithArgument:argument]; float batteryLifeLeft = [iPhone getBatteryLife];Monday, January 14, 13
  • LOOPS AND CONDITIONS Making your code smartMonday, January 14, 13
  • LOOPS • Execute a piece of code multiple times • Automate repetitive tasksMonday, January 14, 13
  • FOR LOOP • Running a ‘for’ loop for ( initialization ; test condition ; increment) { // Code block } for ( int i = 0 ; i < 10 ; i++) { NSLog(@”Hello fellow iOS devs!”); } • This will print “Hello fellow iOS devs!” to the console 10 timesMonday, January 14, 13
  • WHILE LOOP • Running a ‘while’ loop while (condition is true) { // Execute code } BOOL isNetworkConnected = YES; while (isNetworkConnected) { [self downloadData]; } • This will download data so long as the network is connectedMonday, January 14, 13
  • CONDITIONALS • An important idea in programming is taking different actions depending on different circumstances • Conditional expressions are always either true or false • e.g. Is there coffee available in the pantry? If yes, make some coffee. If not, lament in despair (or just go out and buy some)Monday, January 14, 13
  • IF-ELSE STATEMENTS • Writing an if-else statement int number = [self getNumberFromInput]; if (number > 9) { NSLog(@”Number is a double-digit number”); } else if (number == 0) { NSLog(@”Number is not valid”); } else { NSLog(@”Number is a single digit number”); }Monday, January 14, 13
  • COMMON CLASSES • Introduction to a few commonly used classes • Not exhaustiveMonday, January 14, 13
  • NSOBJECT • NSObject is the base class that every object in Objective-C and Cocoa Touch inherits fromMonday, January 14, 13
  • NSSTRING • NSString is an extremely commonly used class • Type for ‘sentences’ or ‘words’ • NSString *myString = @”Hi There!”;Monday, January 14, 13
  • NSARRAY • Type for a collection or ‘array’ of objects grouped together NSArray *weapons = [NSArray arrayWithObjects:@”rifle”, @”pistol”, @”plasma gun”, nil]; Weapon *equippedPistol = [weapons objectAtIndex:1]; • Remember in programming we always start counting from 0Monday, January 14, 13
  • NSDICTIONARY • Type for a collection of objects indexed using key-value pairs NSDictionary *playerData = [NSDictionary dictionaryWithObjectsAndKeys:@”playerWeapons”, @”rifle”, @”highScore”, 9214, @”numberOfLivesLeft”, 3, nil]; int livesLeft = [playerData objectForKey:@”numberOfLivesLeft”];Monday, January 14, 13
  • THANK YOU! Gabriel Lim Getting Real Software Development www.gettingrail.comMonday, January 14, 13