• Save
iOS overview
Upcoming SlideShare
Loading in...5
×
 

iOS overview

on

  • 939 views

Highlevel overview for iOS Development.

Highlevel overview for iOS Development.

Statistics

Views

Total Views
939
Views on SlideShare
921
Embed Views
18

Actions

Likes
1
Downloads
0
Comments
0

3 Embeds 18

http://beyondreading.blogspot.in 10
http://www.techgig.com 6
http://beyondreading.blogspot.com 2

Accessibility

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 overview iOS overview Presentation Transcript

  • iOS – Development Overview
  • iOS Overview Cocoa Touch Core OS Media Core Services OS X Kernel Power management Mach 3.0 Keychain Access Core OS BSD Certificates Sockets File System Security Bonjour2
  • iOS Overview Cocoa Touch Core Services Media Core Services Collections Core Location Address Book Net Services Core OS Networking Threading File Access Preferences SQLite URL Utilities3
  • iOS Overview Cocoa Touch Media Media Core Services Core Audio JPEG, PNG, TIFF OpenAL PDF Core OS Audio Mixing Quartz (2D) Audio Recording Core Animation Video Playback OpenGL4
  • iOS Overview Cocoa Touch Cocoa Touch Media Multi-touch Alerts Core Services Core Motion Web View Core OS View Hierarchy Map Kit Localization Image Picker Controls Camera5
  • Platform Components• Tools• Language [display setTextColor:[UIColor blackColor]];• Frameworks• Design Strategies V6
  • Model View Controller Controller Model View Model – What your application is (but not how it is displayed) Controller– How your model is presented to User (UI Logic) View – Controller’s Minions7
  • iOS Application Structure App Code Boilerplate code Resources Images, Videos, Sound, IB, Data Linked Frameworks, Foundation, Graphics, Sound The Executables Targets (Various Build Settings)8
  • Application Life Cycle int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; }9
  • Objective C CalculatorViewController Controller action x 7 Model View 4 + operationPressed: CalculatorModel UI Buttons digitPressed:10
  • Model Header file CalculatorModel.h Model Name of the class #import <Foundation/Foundation.h> Class’s Superclass @interface CalculatorModel : NSObject { Instance Variable between the double operand; paranthesis }Return Type -(void) setOperand : (double) anOperand; -(double) performOperation : (NSString*)operation; Method declarations Name of the method Method argument @end 11
  • Model Implementation File. CalculatorModel.m Model #import CalculatorModel.h @implementation CalculatorModel -(void) setOperand:(double) anOperand { operand = anOperand; } -(double) performOperation: (NSString*)operation { [ operation sendMessage:argument ]; return aDouble; } @end12
  • Controller View Controller 7 8 9 * 4 5 6 / #import <UIKit/UIKit.h> @interface CalculatorViewController : UIViewController 1 2 3 + { Model C 0 = - CalculatorModel *model; IBOutlet UILabel *display; View } -( IBAction ) digitPressed : ( UIButton *) sender; - (IBAction ) operationPressed : (UIButton *) sender;13
  • 7 8 9 * 4 5 6 / 1 2 3 + C 0 = - Controller14
  • 7 8 9 * Events • digitPressed: - operationPressed: 4 5 6 / 1 2 3 + C 0 = -15
  • Objective C - Methods- (NSArray *)shipsAtPoint:(CGPoint)bombLocation withDamage:(BOOL)damaged; Instance Methods Class Methods • Start with a dash ( - ) • Starts with a plus ( + ), used for • Normal method singletons, allocation, utilities. • Can access instance variables inside as if +(id) alloc; they were locals • Can not access instance variable inside. • can send message to self and super • Message to “Self” and “Super” mean inside something a little different. Both invoke • Example only other “class” methods. Inheritance BOOL destroyed = [ ship does not work. dropBomb:bombType at:dropPoint • Example from:height]; CalculatorModel *model = [[ CalculatorModel alloc] init];16
  • Objective C – Instance Variables Scope By default, instance variables are @protected (only the class and subclass can access). Can be marked @private (only the class can access) or @public (anyone can access) Scope Syntax @interface MyObject: NSObject { int foo; @private int eye; int jet; @protected int bar; @public int forum; int xyz; }17
  • Obj C - Properties • Now forget everything on the previous slide •Mark all instance variable @private • Use @property and dot to access instance variables • Create methods to get/set an instance variable value @interface MyObject : NSObject { @private int eye; } Letter after “set” MUST be capitalized, otherwise dot notation will not work - (int) eye; - (void) setEye : (int) anInt; @end18
  • Obj C - Properties • @property Complier can generate get/set methods declaration with @property directive. @interface MyObject : NSObject { @private int eye; } @property int eye; - (int) eye; hidden - (void) setEye : (int) anInt; @end If “readonly” keyword is used only get method will @property (readonly) int eye; be generated.19
  • Obj C - Properties Implementation (.m) file @implementation MyObject -(int) eye{ return eye; } -(void) setEye:(int)anInt{ eye = anInt; } Compiler can generate set/get methods by using keyword @synthesize @implementation MyObject @synthesize eye; - (int)eye { return eye; } - (void)setEye:(int)anInt { eye = anInt; } @end20
  • Obj C – Dynamic Binding • All objects are allocated to heap, so use pointers • It’s legal to “cast” a pointer. • All objects inherited from NSObjects knows about • isKindOfClass • isMemberOfClass • respondToSelector21
  • Frameworks Foundation Framework • NSObject • Base class for pretty much every object in the iOS SDK. • Implements memory management primitives • NSString • Unicode • Used throughout iOS instead of C language char * • An NSString instance can not be modified. They are immutable • NSMutableString • Mutable version of NSString. • NSNumber, NSData, NSDate • NSArray, NSMutableArray • NSDictionary, NSMutableDictionary • NSSet, NSMutableSet • NSUserDefaults22
  • Creating Objects Two Step process -allocate -Initiate alloc makes space in heap for class’s instance variables. Each class has a designated “initializer” method. MyObject *obj = [ [ MyObject alloc] init];23
  • Getting Objects alloc/init is not the only way to “get” an object. Plenty of classes give the object if you ask for it. NSString *newDisplay = [ display.text stringByAppendingString:digit ]; NSArray *keys = [ dictionary allKeys]; Who frees the memory for all these objects? No Garbage collection in iOS Answer lies in “reference counting”24
  • Reference Counting -Take the ownership for an object you want to keep a pointer to - When you are done with the object, you give up the ownership - When no one claims ownership for an object, it gets de allocated. So when do we take the ownership? Own any object as soon as we send a msg with new, alloc, or copy. But if we receive the object from any other source you don’t own it, but we can take ownership by sending it the NSObject message “retain”. The object which we receive from any other source, we’ll own it temporarily until the call stack unwinds Or, the object is retained. Once we are done with the object, send the object the NSObject message “release”. We now own theMoney, we got it using the method alloc. We are responsible for -(Money *) showMeTheMoney:(double) amount { sending it release Money *theMoney = [[ Money alloc] init:amount]; [theMoney autorelease]; We’ve now released the object but it won’t happen return Money; until the caller of this method has had chance to retain to theMoney if they want. } Caller Money *myMoney = [ bank showMeTheMoney:5000]; [myMoney retain];25
  • Deallocation What happens when the last owner calls release? A special method, dealloc, is called on the object & the object’s memory is returned to the heap. After this happens, sending a message to the object will crash the program. Override “dealloc” in your class but NEVER call it !!! [ Strange ? ] It only gets called by release when the last owner has ‘released’ the object. The one exception about calling it is that you should call [super dealloc] in your dealloc. Example - (void) dealloc { [brain release]; [super dealloc]; }26
  • @property Example display.text = [display.text stringByAppendingString:digit]; This is still owned by display (the UILabel). We don’t This is the NSString we acquired. It comes back retain it because we are not going to keep it. We’re autoreleased. We’re not going to retain this one either just going to use it to acquire a different NSString b’cause we’re just going to pass it on to display’s text from stringByAppendingString property setter method. Setting an instance variable via setter method (via property) Did we retain that object? We need to retain instance variable and this can be done via setter methods but what about @synthesis There are 3 options for setters made by @synthesis @property (retain) NSArray *myArrayProperty; @property (copy) NSString *someNameProperty; @property (assign) id delegate; The first 2 options are straight forward. The third option means that neither retain nor copy is sent to the object passed to the setter. This means that if this object is released by all other owners, we’ll have a bad pointer. So we only use “assign” if the passed object essentially owns the object with the property. A controller and its views (b’cause a View should never outlive its controller) A View can have a property (delegate is very common) which is assigned to its controller.27
  • @property examples @property (retain) NSString *name; @synthesis will create a setter equivalent to -(void) setName:(NSString *) aString @synthesis will release the retain previous object (if any, could be { nil) before setting and retaining the [name release]; new one. name = [aString retain]; } @property (copy) NSString *name; @synthesis will create a setter equivalent to copy -(void) setName:(NSString *) aString { [name release]; name = [aString copy]; }@property (assign) NSString *name;@synthesis will create a setter equivalent to assign-(void) setName:(NSString *) aString{ name = aString;}28
  • #import <Foundation/Foundation.h> @protocol ProcessDataDelegate <NSObject> @required - (void) processSuccessful: (BOOL)success; @end protocols Protocols can be useful in a number of cases, a common usage is to define method that are to be implemented by other classes. Similar to @interface, but no implementation @protocol Foo -(void) doSomething; // implementors must implement @optional -(int) getSomething; // Optional to implement. Class that implement will look like @interfaceMyClass : NSObject <Foo> … @end Use of protocols are mainly in delegates and dataSources The delegate or dataSource is always defined as an assign @property @property (assign) id <UISomeObjectDelegate> delegate; 29
  • Protocols#import <Foundation/Foundation.h> #import "ClassWithProtocol.h"@protocol ProcessDataDelegate <NSObject> @implementation ClassWithProtocol-(void) processSuccessful: (BOOL)success; @synthesize delegate;@end -(void)processComplete { [[self delegate] processSuccessful:YES];@interface ClassWithProtocol : NSObject { } id <ProcessDataDelegate> delegate; -(void)startSomeProcess {} [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(processComplete) userInfo:nil repeats:YES];@property (retain) id delegate; }-(void)startSomeProcess;@end 30
  • Application Delegate Class that adopts the protocol.HappinessAppDelegate.h (header file for Application Delegate) This object implements the UIApplicationDelegate protocol. The applicationDidxxx and applicationWillxxx@interface HappinessAppDelegate : NSObject <UIApplicationDelegate> methods{ UIWindow *window; Instance Variable/property/outlet HappynessViewController *viewController; pointing to HappynessViewController} (our controller) also hooked up to MainWindow.xib@property (nonatomic, retain) IBOutlet UIWindow *window;@property (nonatomic, retain) IBOutlet HappynessViewController *viewController;@end Instance Variable/property/outlet pointing to the top-level view for this application (UIWindow). This is hooked up to MainWindow.xib31
  • Adopting Protocol & Delegate#import <UIKit/UIKit.h> #import "TestAppDelegate.h" #import "ClassWithProtocol.h"#import "ClassWithProtocol.h" @implementation TestAppDelegate@interface TestAppDelegate : NSObject <UIApplicationDelegate, ProcessDataDelegate> @synthesize window; UITableViewDelegate{ -(void)processSuccessful:(BOOL)success; { UIWindow *window; NSLog(@"Process completed"); ClassWithProtocol *protocolTest; }} -(void)applicationDidFinishLaunching:(UIApplication *)application@property (nonatomic, retain) UIWindow *window; { // Create and initialize the window@end window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; protocolTest = [[ClassWithProtocol alloc] init]; [protocolTest setDelegate:self]; [protocolTest startSomeProcess]; [window makeKeyAndVisible]; } -(void)dealloc { [window release]; [super dealloc]; } 32 @end