Download presentation
Presentation is loading. Please wait.
Published byIris McKenzie Modified over 9 years ago
1
Objective-C for C# and Java Developers JaxCodeCamp 2012
2
Who am I David Fekke.NET Developer by day, iOS by night Presenter JaxMUG, JaxDug, JaxJug, JSSUG Mac User 1986
3
JaxMUG Meet once a month at the Southside Library jaxmug.com
4
Alan Kay Smalltalk is object-oriented, but it should have been message oriented.
5
Alan Kay When I invented the term Object-Oriented, and I can tell you I did not have C++ in mind.
6
Bjarne Stroustrup C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg.
7
Jesse Eisenberg
8
The Apple Way
9
Assumptions Somewhat familiar with OO concepts Used a language like Java, C# or C++ Open minded Actually used an iPhone, iPad or iPod Touch
10
Requirements You need a Intel Mac with Mac OS X Some knowledge of OO concepts Xcode tools (FREE) iOS (SDK)
11
Developer Programs iPhone Individual ($99) iPhone Enterprise ($399) iPhone Student
12
App Store Submit Apps with Individual program Apple keeps 30%, you keep 70% Refunds: you pay 100%
13
iOS Platform ARM Processor 128/256/512/1024 MB RAM BSD UNIX Mach Microkernel COCOA APIs
14
COCOA COCOA is a OO Framework Based on NextStep Mostly written in Objective-C iOS Devices use COCOA Touch
15
Cocoa Touch Media Core Services Core OS
16
COCOA Framework NS (NextStep) CF (Core Foundation) CA (Core Animation) CI (Core Image) Core Data OpenGL ES
17
COCOA Conventions Most classes begin with NS, I.E. NSObject, NSString, NSArray or NSNumber Designed around MVC pattern Heavy use of delegation iOS specific components based on UIKit
18
COCOA Touch APIs Accelerometer Location API Multi-Touch Camera/Video Input Map Interface* OpenGL ES
19
Tiobe Programming Index PositionLanguage 1C 2Java 3Objective-C 4C++ 5C#
20
Objective-C Somewhere in-between C++ and Java Created by Brad Cox and Tom Love in 1982 Based on C with SmallTalk like extentions Used in COCOA, OpenStep and GNUStep Class based OO language
21
-(BOOL)validateNumRangeWithStartNumber:(int)startNumber EndNum:(int) endNumber { if (startNumber >= endNumber) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"End value Too Small" message:@"Sorry" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; [alertView release]; return YES; } else { return NO; }
22
Obj-C vs C# Obj-CC# [[object method] method];obj.method().method(); Memory PoolsGarbage Collection +/-static/instance nilnull (void)methodWithArg:(int)value {} void method(int value) {} YES NO true false @protocol interface
23
Objective-C Structure Obj-C Class composed of two files: header and implementation, or.h and.m header uses the @interface and implementation uses @implementation
24
#import @interface LottoRandomAppDelegate : NSObject { UIWindow *window; } @property (nonatomic, retain) IBOutlet UIWindow *window; @end
25
#import "LottoRandomAppDelegate.h" @implementation LottoRandomAppDelegate @synthesize window; - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after application launch [window makeKeyAndVisible]; } - (void)dealloc { [super dealloc]; } @end
26
Properties Objective-C 2.0 @property (strong) NSString *myStr; @synthesize myStr = _myStr; No longer need @synthesize keyword in iOS 6.0
27
Property Getters and Setters @synthesize myStr = _myStr; -(NSString *)myStr { return _myStr; } -(void)setMyStr:(NSString *)aMyStr { _myStr = aMyStr; }
28
@interface extension @interface MasterViewController () { NSMutableArray *_objects; } @end
29
Categories Similar to method extensions and partial classes You can add methods to classes out side of the implementation file
30
@interface NSString (reverse) -(NSString *) reverseString; @end @implementation NSString (reverse) -(NSString *) reverseString { NSMutableString *reversedStr; int len = [self length]; // Auto released string reversedStr = [NSMutableString stringWithCapacity:len]; // Probably woefully inefficient... while (len > 0) [reversedStr appendString:[NSString stringWithFormat:@"%C", [self characterAtIndex:--len]]]; return reversedStr; } @end
31
Blocks C constructs for performing closures Similar to Lamda expressions in C# ^{... Code goes here... } Newer Obj-C APIs require blocks Used heavily in GCD
32
dispatch_queue_t myQueue = dispatch_queue_create("get people list", NULL); dispatch_async(myQueue, ^{ NSURL *myURL = [NSURL URLWithString:@"http://192.168.1.70/APISamples/api/people"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL]; [request setHTTPMethod:@"GET"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; NSURLResponse *response = nil; NSError *myErr; NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&myErr]; _objects = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&myErr]; dispatch_async(dispatch_get_main_queue(), ^{ [self.tableView reloadData]; }); // Ending main queue }); // End myQueue
33
Selectors SEL type defines a method signature -(void)setAction:(SEL)aSelector SEL mySelector; mySelector = @selector(drawMyView:); [myButton setAction:mySelector];
34
Objective-C Literals New in iOS 6 and Mac OS X 10.8 NSArray *array = @[ @"Hello", NSApp, [NSNumber numberWithInt:42] ]; NSDictionary *dictionary = @{ @"name" : NSUserName(), @"date" : [NSDate date], @"processInfo" : [NSProcessInfo processInfo] };
35
Memory Management C used methods like malloc and free Obj-C uses object retain pool Garbage Collection on the Mac, but not on the iOS Devices Use ARC for future implementations
36
Memory Management Cont. NSString *myName = [[NSString alloc] init]; // retain count of 1 [myName retain]; // retain count of 2 [myName release]; // retain count reduced to 1 [myName autorelease]; // object released by pool magically
37
ARC Automatic Reference Counting Not Garbage Collection Compiler adds memory management into the compiled code Use Strong and Weak keywords to give hint to the compiler
38
MVC Model-View-Controller COCOA has Controller classes UIViewController Class Views are in the XIB (NIB) files or StoryBoards
39
Controllers iPhone Apps commonly have multiple views Controllers can Segue to each View Navigation Controller used to load different views UINavigationController
40
SDK Tools Xcode 4.5 IDE Interface Builder (Views) Instruments (Profiler tool) iPhone Simulator
41
Xcode 4.5 LLVM, Clang and GCC compiler 4.2 Support for Obj-C, C++, Python and Ruby (iPhone only uses Obj-C & C++) Code editor with code completion Support for GIT, SVN and CVS
42
Interface Builder Tool for laying out interfaces Built into Xcode StoryBoards for Mobile Also works with older XIB and NIB files Bind Actions and Outlets in Controllers
43
Demo
44
Internet Resources http://developer.apple.com http://developer.apple.com/iphone/librar y/documentation/Cocoa/Conceptual/Obj ectiveC/ http://developer.apple.com/iphone/librar y/documentation/Cocoa/Conceptual/Obj ectiveC/ http://www.stanford.edu/class/cs193p/c gi-bin/index.php http://www.stanford.edu/class/cs193p/c gi-bin/index.php http://www.cocoadev.com/ http://www.cocoadev.com
45
Book Resources COCOA Programming For Mac OS X by Aaron Hillegass iPhone Developer’s Cookbook by Erica Sadun APress Books
46
Snow Leopard Mac OS X 10.6 released yesterday Optimized for 64bit Xcode 3.2 Static Analysis Code warning and hinting OpenCL Library Grand Central Dispatch
47
Mono Touch Develop iPhone Apps with C# Xamarin IDE Ahead of time compilation Works with IB
48
PhoneGap HTML, CSS and JavaScript Compiles into an.app that can be uploaded to the app store Native vs. Run everywhere Also Sencha Touch
49
Contact davidfekke at gmail dot com twitter.com/davidfekke http://www.fekke.com/blog/ Please come out to the JaxMUG
50
Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.