Introduction to iphone OS _2 Dept. of Multimedia Science, Sookmyung Women s University. Prof. JongWoo Lee
Index iphone SDK - - - Xcode Interface Builder Objective-C Dept. of Multimedia Science, Sookmyung Women s University. Prof. JongWoo Lee
iphone SDK
iphone OS - Core OS Free BSD UNIX - Core Services iphone OS Core Foundation :,, - Media Media Player - Cocoa Touch Core Data:, SQLite Address Book: API Quarts : Core Graphics, OPenGL ES, Quartz Core Core Audio: Audio Toolbox, Audio Unit, AVFoundation, OpenAL user application UIKit framework View,, control
- iphone SDK iphone - Xcode (IDE, Integrated Development Environment) - Interface Builder - iphone Simulator
iphone SDK(1/2) iphone SDK - : http://developer.apple.com/iphone/ ( ) - ios 4.0 Xcode 3.2.3 iphone SDK 4 - DMG OS (MS ISO )
iphone SDK(2/2) iphone SDK - Xcode and iphone SDK for Snow Leopard -! - SDK /Developer - Xcode /Developer/Application
Hello World! Xcode
Xcode Xcode - /Developer/Application - Dock finder - Macintosh HD/Developer/Applications/Xcode -, Dock Xcode
Xcode - (1/2) - File [New Project...] View-based Application
- Xcode - (2/2) Hello World
Xcode - Xcode Hello World Detail View Groups & files Groups & files
Xcode Groups & Files Classes Xcode - Groups & Files Other Sources Objective-C _Prefix.pch :, main.m : main(), Resources,, MainWindow.xib : ViewController.xib : Info.plist : Property list Framework,,,
iphone. Interface Hello world Builder! Hello_WorldViewController.xib!
Hello World! Interface Builder
Interface Builder Hello_WorldViewController.xib View main Library ( ) Inspector
Interface Builder Hello_WorldViewController.xib - nib - nib File s Owner First Responder, - File s Owner nib nib - First Responder, first responder first responder first responder - View - UIView - 4 View
Interface Builder?!, - UIButton, UIButton *mybutton = [[UIButton alloc] initwithframe:arect]; Interface Builder
View - - - Interface Builder - Library nib Label View Label : Label Hello, World!
Hello World Interface Builder - command+s Xcode - - Build/ Build and Run iphone Simulator
!
! - MVC Hello World -! - - (MVC; Model-View-Controller) - MVC - GUI - Model - View UI - Controller
, Hello World!
Hello World Hello_WorldViewController.h ( ) #import <UIKit/UIKit.h> // //UIViewController Hello_WorldViewController @interface Hello_WorldViewController : UIViewController { UILabel * statustext; } // Interface Builder nib @property (nonatomic, retain) IBOutlet UILabel *statustext;!! // // Interface Builder - (IBAction)LbuttonPressed:(id)sender; - (IBAction)RbuttonPressed:(id)sender; // @end Hello_WorldViewController.h - : IBOutlet nib (nib ) - : IBAction
Hello World Hello_WorldViewController.m Hello_WorldViewController.m ( ) #import "Hello_WorldViewController.h" @implementation Hello_WorldViewController @synthesize statustext; // - (IBAction)LbuttonPressed:(id)sender { //. NSString *title = [sender titleforstate:uicontrolstatenormal]; NSString *newtext = [[NSString alloc] initwithformat:@"%@.", title]; statustext.text = newtext; // alloc release. [newtext release]; } // - (IBAction)RbuttonPressed:(id)sender { NSString *title = [sender titleforstate:uicontrolstatenormal]; NSString *newtext = [[NSString alloc] initwithformat:@"%@.", title]; statustext.text = newtext; [newtext release]; } - (void)dealloc {! [statustext release]; [super dealloc]; } @end
Hello World Hello_WorldAppDelegate.h Hello_WorldAppDelegate.h ( - ) #import <UIKit/UIKit.h> @class Hello_WorldViewController; Delegate : UIApplication UIKit UIApplication UIApplication //<UIApplicationDelegate> @interface Hello_WorldAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; Hello_WorldViewController *viewcontroller; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet Hello_WorldViewController *viewcontroller; @end UIApplicationDelegate option!
Hello World Hello_WorldAppDelegate.m Hello_WorldAppDelegate.m ( - ) #import "Hello_WorldAppDelegate.h" #import "Hello_WorldViewController.h" @implementation Hello_WorldAppDelegate @synthesize window; @synthesize viewcontroller; // - (BOOL)application:(UIApplication *)application didfinishlaunchingwithoptions: (NSDictionary *)launchoptions { // Override point for customization after application launch. // Add the view controller's view to the window and display. [window addsubview:viewcontroller.view]; [window makekeyandvisible]; } return YES; - (void)dealloc { [viewcontroller release]; [window release]; [super dealloc]; } @end Xcode Interface Builder!
Hello World Hello_WorldViewController.xib Hello_WorldViewController.xib - View - Label Attributes - Attributes, command+1
Hello World Hello_WorldViewController.xib Round Rect Button View!
Hello World Hello_WorldViewController.xib File s Owner (IBOutlet) File s Owner View statustext
Hello World Hello_WorldViewController.xib - View command+2 connections inspector. - Touch Up Inside. Touch Up Inside :, Touch Up Inside - Touch Up Inside File s Owner - LbuttonPressed - Touch Up Inside, RbuttonPressed
Hello World!! Interface Builder Xcode!!
Objective-C
Objective-C? 1980 C iphone Framework Library Objective-C C C/C++, C# Objective-C.h, class interface.m C, Objective-C implementation.mm Objective-C C++
Objective-C - -. [ ] - ; [ : ] ) [object method]; [object methodwithinput:input]; output = [object methodwithoutput] output = [object methodwithinputandoutput:input]; - ) id myobject = [NSString string]; (id? myobject ), NSString* mystring = [NSString string]; ( Objective-C * ) - mywidget PowerOn ) Objective-C returnvalue = [mywidget poweron]; C++ returnvalue = mywidget PowerOn(); C returnvalue = widget_poweron(mywidget);
Import - #include #import Objective-C - Objective-C Private -, - ) [photo setcaption:@ Day at the Beach ]; output = [photo caption]; // caption Objective-C getter get -.(dot).(dot) (getter and setter) Objective-C 2.0 ) photo.caption = @ Day at the Beach ; output = photo.caption;
Objective-C property - - interface ) @property (nonatomic, retain) IBOutlet UILabel *statustext;! nonatomic - retain - Objective-C - implementation @synthesize statustext; String - c String - Objective-C framework NSString - @ ) NSString *mystring = @"My String\n"; NSString *anotherstring = [NSString stringwithformat:@"%d %s", 1, @"String"]; // Create an Objective-C string from a C string NSString *fromcstring = [NSString stringwithcstring:"a C string" encoding:nsasciistringencoding];
Objective-C (.h) @interface MyClass : NSObject { int count; id data; NSString* name; } // interface.h.m implementation - (id)initwithstring : (NSString*)aName; + (MyClass*)createMyClassWithString:(NSString*)aName; @end // + ( ) - ( ) implementation(.m) @implementation MyClass -(id)initwithstring:(nsstring *)aname; { if(self = [super init]){ name = [aname copy]; } return self; } + (MyClass*)createMyClassWithString:(NSString*)aName; { return [[[self alloc] initwithstring:aname] autorelease]; } @end
Objective-C - (void)insertobject:(id)anobject atindex:(nsuinteger)index - [myarray insertobject:anobject atindex:0]; - ([ [] ]) [[myappobject thearray] insertobject:[myappobject objecttoinsert] atindex:0]; -.( ) accessor methods(, getter or setter) [myappobject.thearray insertobject:[myappobject objecttoinsert] atindex:0]; myappobject.thearray = anewarray;
- command + space bar - command + s - command + a, command + c, command + v
iphone OS Hello World