SlideShare a Scribd company logo
1 of 29
Download to read offline
OBJECTIVE-C AND YOU
                         First step on your Journey to writing iOS apps




Monday, 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
        world


Monday, 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 easier




Monday, January 14, 13
PREREQUISITES

    • An         Intel-based Mac

    • Xcode              IDE




Monday, 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
        programming




Monday, 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 programming




Monday, 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, BOOL




Monday, 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 smart




Monday, January 14, 13
LOOPS
    • Execute            a piece of code multiple times

    • Automate             repetitive tasks




Monday, 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 times



Monday, 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 connected



Monday, 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           exhaustive




Monday, January 14, 13
NSOBJECT
    • NSObject   is the base class that every object in Objective-C
        and Cocoa Touch inherits from




Monday, 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 0


Monday, 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.com

Monday, January 14, 13

More Related Content

Similar to iOS Hackathon 2012 Objective-C talk

Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)Altece
 
Objective-C A Beginner's Dive
Objective-C A Beginner's DiveObjective-C A Beginner's Dive
Objective-C A Beginner's DiveAltece
 
Node.js Patterns and Opinions
Node.js Patterns and OpinionsNode.js Patterns and Opinions
Node.js Patterns and OpinionsIsaacSchlueter
 
Sqlpo Presentation
Sqlpo PresentationSqlpo Presentation
Sqlpo Presentationsandook
 
Native Javascript apps with PhoneGap
Native Javascript apps with PhoneGapNative Javascript apps with PhoneGap
Native Javascript apps with PhoneGapIbuildings
 
Tokyo iOS Meetup - 409 - Testing In XCode
Tokyo iOS Meetup - 409 - Testing In XCodeTokyo iOS Meetup - 409 - Testing In XCode
Tokyo iOS Meetup - 409 - Testing In XCodeippoipposoftware
 
Lessons from my work on WordPress.com
Lessons from my work on WordPress.comLessons from my work on WordPress.com
Lessons from my work on WordPress.comVeselin Nikolov
 
Runtime Innovation - Nextgen Ninja Hacking of the JVM, by Ryan Sciampacone
Runtime Innovation - Nextgen Ninja Hacking of the JVM, by Ryan SciampaconeRuntime Innovation - Nextgen Ninja Hacking of the JVM, by Ryan Sciampacone
Runtime Innovation - Nextgen Ninja Hacking of the JVM, by Ryan SciampaconeZeroTurnaround
 
IOTDB - Semantic Metadata for the Internet of Things
IOTDB - Semantic Metadata for the Internet of ThingsIOTDB - Semantic Metadata for the Internet of Things
IOTDB - Semantic Metadata for the Internet of ThingsDavid Janes
 
Basics of coding
Basics of codingBasics of coding
Basics of codingSanaaSharda
 
IOTDB - #IoTDay 2014 Presentation
IOTDB - #IoTDay 2014 PresentationIOTDB - #IoTDay 2014 Presentation
IOTDB - #IoTDay 2014 PresentationDavid Janes
 

Similar to iOS Hackathon 2012 Objective-C talk (15)

Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)
 
Objective-C A Beginner's Dive
Objective-C A Beginner's DiveObjective-C A Beginner's Dive
Objective-C A Beginner's Dive
 
Node.js Patterns and Opinions
Node.js Patterns and OpinionsNode.js Patterns and Opinions
Node.js Patterns and Opinions
 
Sqlpo Presentation
Sqlpo PresentationSqlpo Presentation
Sqlpo Presentation
 
Native Javascript apps with PhoneGap
Native Javascript apps with PhoneGapNative Javascript apps with PhoneGap
Native Javascript apps with PhoneGap
 
Tokyo iOS Meetup - 409 - Testing In XCode
Tokyo iOS Meetup - 409 - Testing In XCodeTokyo iOS Meetup - 409 - Testing In XCode
Tokyo iOS Meetup - 409 - Testing In XCode
 
CV-PHAM VAN THINH
CV-PHAM VAN THINHCV-PHAM VAN THINH
CV-PHAM VAN THINH
 
Lessons from my work on WordPress.com
Lessons from my work on WordPress.comLessons from my work on WordPress.com
Lessons from my work on WordPress.com
 
Runtime Innovation - Nextgen Ninja Hacking of the JVM, by Ryan Sciampacone
Runtime Innovation - Nextgen Ninja Hacking of the JVM, by Ryan SciampaconeRuntime Innovation - Nextgen Ninja Hacking of the JVM, by Ryan Sciampacone
Runtime Innovation - Nextgen Ninja Hacking of the JVM, by Ryan Sciampacone
 
IOTDB - Semantic Metadata for the Internet of Things
IOTDB - Semantic Metadata for the Internet of ThingsIOTDB - Semantic Metadata for the Internet of Things
IOTDB - Semantic Metadata for the Internet of Things
 
Using SQLite
Using SQLiteUsing SQLite
Using SQLite
 
Oop lec 2
Oop lec 2Oop lec 2
Oop lec 2
 
Basics of coding
Basics of codingBasics of coding
Basics of coding
 
Technical Interviewing
Technical InterviewingTechnical Interviewing
Technical Interviewing
 
IOTDB - #IoTDay 2014 Presentation
IOTDB - #IoTDay 2014 PresentationIOTDB - #IoTDay 2014 Presentation
IOTDB - #IoTDay 2014 Presentation
 

iOS Hackathon 2012 Objective-C talk

  • 1. OBJECTIVE-C AND YOU First step on your Journey to writing iOS apps Monday, January 14, 13
  • 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 world Monday, January 14, 13
  • 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 easier Monday, January 14, 13
  • 4. PREREQUISITES • An Intel-based Mac • Xcode IDE Monday, January 14, 13
  • 5. OBJECTIVE-C BASICS And a random motorcycle. Monday, January 14, 13
  • 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 programming Monday, January 14, 13
  • 7. WHY OBJECTIVE-C? • Use Objective-C if you don’t want your app to suck. Seriously. Monday, January 14, 13
  • 8. OBJECT ORIENTATION • Using objects as ‘data models’ •A way to think about programming Monday, January 14, 13
  • 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. 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. 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. DECLARING DATA TYPES int cupsOfCoffee; int amountOfWork float productivityLevel; cupsOfCoffee = 3; productivityLevel = cupsOfCoffee * amountOfWork; Monday, January 14, 13
  • 13. DEFINING VARAIBLES Class *objectName; - NSString *mySentence; What is the * ? Not for C types like int, float, BOOL Monday, January 14, 13
  • 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. 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. 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. METHODS • Invoking Methods on Objects [object method]; [object methodWithArgument:argument]; int variable = [object methodWithArgument:argument]; float batteryLifeLeft = [iPhone getBatteryLife]; Monday, January 14, 13
  • 18. LOOPS AND CONDITIONS Making your code smart Monday, January 14, 13
  • 19. LOOPS • Execute a piece of code multiple times • Automate repetitive tasks Monday, January 14, 13
  • 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 times Monday, January 14, 13
  • 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 connected Monday, January 14, 13
  • 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. 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. COMMON CLASSES • Introduction to a few commonly used classes • Not exhaustive Monday, January 14, 13
  • 25. NSOBJECT • NSObject is the base class that every object in Objective-C and Cocoa Touch inherits from Monday, January 14, 13
  • 26. NSSTRING • NSString is an extremely commonly used class • Type for ‘sentences’ or ‘words’ • NSString *myString = @”Hi There!”; Monday, January 14, 13
  • 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 0 Monday, January 14, 13
  • 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. THANK YOU! Gabriel Lim Getting Real Software Development www.gettingrail.com Monday, January 14, 13