Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Objective-C For Web Developers

Objective-C For Web Developers

Talk given at TechFest Northwest Arkansas 2012

Avatar for Addam Hardy

Addam Hardy

August 24, 2012
Tweet

More Decks by Addam Hardy

Other Decks in Programming

Transcript

  1. strict superset of C compiled language object-oriented dynamic strictly typed

    smalltalk style messaging very verbose Objective-C
  2. typing Ruby PHP Objective-C $var = 21; $variable = “This

    is a string”; var = 21 variable = “This is a string” (int) var = 21; NSString *variable = @“This is a string”;
  3. typing C Primitives Common Classes char short long unsigned char

    unsigned int int float double bool NSString NSNumber NSArray NSDictionary NSMutableArray NSMutableDictionary UIView UIButton id and 20,000 others..
  4. headers / implementation class.h The public API for the class

    @interface Student { NSNumber *age; NSString *name; } @end
  5. headers / implementation class.h class.m The public API for the

    class The instructions for the class @interface Student { NSNumber *age; NSString *name; } @end @implementation Student - (NSString *) name { } @end
  6. classes Ruby PHP class HelloWorld { // instance variables go

    here // methods go here public function sayHI() { print("Hello World!”); } } class HelloWorld // instance variables go here // methods go here def sayHI puts "Hello World!” end end
  7. classes Ruby PHP class cat extends animal { public function

    be_cute() { print("I am teh cute”); } } class cat < animal def be_cute puts "I am teh cute” end end
  8. Objective-C #import <Foundation/Foundation.h> #import "HelloWorld.h" int main (int argc, const

    char * argv[]) { HelloWorld *hw = [[HelloWorld alloc] init]; [hw printHelloDate]; return 0; } object instantiation main.m
  9. methods / selectors Ruby PHP function buyItem(item) { $cart =

    new ShoppingCart; $cart->purchase(item); } def buyItem(item) cart = ShoppingCart.new cart.purchase(item) end
  10. common pitfalls NSString *this = @”kitty”; NSString *that = @”kitty”;

    if(this == that){ NSLog(@”This will not happen”); } if([this isEqualToString:that]){ NSLog(@”This will happen!”); } NO YES