Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

iOS Hackathon 2012 Objective-C talk

846 views

Published on

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

  • Be the first to comment

  • Be the first to like this

iOS Hackathon 2012 Objective-C talk

  1. 1. OBJECTIVE-C AND YOU First step on your Journey to writing iOS appsMonday, January 14, 13
  2. 2. 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
  3. 3. 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
  4. 4. PREREQUISITES • An Intel-based Mac • Xcode IDEMonday, January 14, 13
  5. 5. OBJECTIVE-C BASICS And a random motorcycle.Monday, January 14, 13
  6. 6. 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
  7. 7. WHY OBJECTIVE-C? • Use Objective-C if you don’t want your app to suck. Seriously.Monday, January 14, 13
  8. 8. OBJECT ORIENTATION • Using objects as ‘data models’ •A way to think about programmingMonday, January 14, 13
  9. 9. 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
  10. 10. MORE VOCABULARY • Class - Car • Instance - BMW Z4 • Methods - Drive, convert roof, attract women • Variables - Amount of fuel, speed (km/h)Monday, January 14, 13
  11. 11. 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
  12. 12. DECLARING DATA TYPES int cupsOfCoffee; int amountOfWork float productivityLevel; cupsOfCoffee = 3; productivityLevel = cupsOfCoffee * amountOfWork;Monday, January 14, 13
  13. 13. DEFINING VARAIBLES Class *objectName; - NSString *mySentence; What is the * ? Not for C types like int, float, BOOLMonday, January 14, 13
  14. 14. 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
  15. 15. 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
  16. 16. 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
  17. 17. METHODS • Invoking Methods on Objects [object method]; [object methodWithArgument:argument]; int variable = [object methodWithArgument:argument]; float batteryLifeLeft = [iPhone getBatteryLife];Monday, January 14, 13
  18. 18. LOOPS AND CONDITIONS Making your code smartMonday, January 14, 13
  19. 19. LOOPS • Execute a piece of code multiple times • Automate repetitive tasksMonday, January 14, 13
  20. 20. 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
  21. 21. 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
  22. 22. 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
  23. 23. 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
  24. 24. COMMON CLASSES • Introduction to a few commonly used classes • Not exhaustiveMonday, January 14, 13
  25. 25. NSOBJECT • NSObject is the base class that every object in Objective-C and Cocoa Touch inherits fromMonday, January 14, 13
  26. 26. NSSTRING • NSString is an extremely commonly used class • Type for ‘sentences’ or ‘words’ • NSString *myString = @”Hi There!”;Monday, January 14, 13
  27. 27. 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
  28. 28. 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
  29. 29. THANK YOU! Gabriel Lim Getting Real Software Development www.gettingrail.comMonday, January 14, 13

×