iPhone Development 박종화 suakii@gmail.com Contents • Requirements • iOS SDK • iOSOverView • Objective-C • Design Pattern • App Dev Cycle • QA Trend Smartphone OS 2009 2010 /표준 /표준 /표준/표준 /표준 /표준/표준 /표준 /표준 /표준 Symbian Research In Motion Android iOS Microsoft Windows Mobile /표준 /표준 /표준/표준 Linux Other OSs Smartphone OS Microsoft Windows Mobile 5% Linux Other OSs 3% 2% Symbian 41% iOS 14% Android 17% Research In Motion 18% Why? Differences • • • • • • • Only One Running Application Only One Window Limited Access Limited Response Time Limited Screen Size Limited System Resources No Garbage Collection Requirements Requirements • Intel Based Snow Leopard • iPhone or iPod Touch • Xcode • iOSSDK • Objected Oriented Concepts Hardware Hardware Hardware Hardware Software Developer Programs • iOS Developer – Individual ($99/year) • iOS Developer – Enterprise ($299/year) • iOS Developer – Student ($0) iPhone Platform • ARM Processor(Samsung, Apple) • 512MB RAM (iPhone4) • BSD UNIX • Mach kernel • COCOA APIs iOS SDK SDK Tools • Frameworks • Xcode Tools • iPhone Simulator • iPhone Reference Library Frameworks • Apple delivers most of its system interfaces in special packages called frameworks. • A framework is a directory that contains a dynamic shared library and the resources need to support that library Frameworks Xcode Tools Xcode Interface Builder Instruments Xcode Interface Builder Instruments Xcode Tools • GCC compiler 4.2 • Support for Obj-C, C++, Java, Python and Ruby (iPhone only uses Obj-C & C++) • Code editor with code completion • Support for SVN and CVS Interface Builder • Tool for laying out interfaces • Separate Tool from Xcode • Bind Actions and Outlets in Controllers Simulator Simulator Simulator iOS OverView iOS 4.1 • Multitasking • Folders • Threaded email • iBooks • Game Center • Not support Flash or Java iOS Cocoa Touch Core OS OSX Kernel Power Management Media Core Services Core OS Mach 3.0 Keychain Access BSD Certificates Sockets File System Security Bonjour iOS Cocoa Touch Media Core Services Core OS Core Services Collections Core Location Address Book Net Services Networking Threading File Access Preferences SQLite URL Utilities iOS Cocoa Touch Media Core Services Core OS Media Core Audio JPEG, PNG, TIFF OpenAL PDF Audio Mixing Quartiz (2D) Audio Recording Core Animation Video Playback OpenGL ES iOS Cocoa Touch Media Core Services Core OS Cocoa Touch Multi-Touch Alerts Core Motion Web View View Hierarchy Map Kit Localization Image Picker Controls Camera Application Life Cycle Event-Handling Interruptions Main.m #import <UIKit/UIKit.h> int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; } Performance • • • • • • • Do Not Block the Main Thread Use Memory Efficiently Floating-Point Math Considerations Reduce Power Consumption Tune Your Code Improve File Access Times Tune Your Networking Code Objective-C OO Terms • • • • • • • • Class Instance Message Method Instance Variable Inheritance Superclass/Subclass Protocol History Objective-C • • • • • • Somewhere in-between C++ and Java Created by Brad Cox & Tom Love Invented in 1980’s for Next Computing Based on C with SmallTalk like extentions Used in COCOA, OpenStep and GNUStep Class based OO language Objective-C • • 객체를 중심으로 작성 • 동작을 객체의 method, 객체의 데이터를 instance variable • Objective-C는 동적인 언어로서 실행시에 객체나 매소드가 변할 수 있다. 객체는 데이터와 데이터를 조작하는 동작으로 이루어진다. Class Interface #import <UIKit/Uikit.h> @interface HelloWorldViewController : UIViewController { //Instance Variable UIButton button; UILabel *label; } //property @property (nonautomatic, retain) IBOutletUILabel *label; //method -(IBAction)sayHello:(id)sender; @end Class Implementation #import “HelloWorldViewController.h” @implementation HelloWorldViewController @synthesize label; -(IBAction) sayHello:(id) sender { label.text = @”Hello, World”; } -(void)viewDidLoad { } -(void)dealloc { [label release]; [super dealloc]; } @end Class Allocation • HelloWorldViewController *obj = [[HelloWorldViewControlleralloc] init]; Property • 인스턴스 변수에 대한 접근자메소드의 구현의 편리 label - getter • • setLabel: - setter @synthesize Dot Syntax label.text = @”Hello, World”; [label setText:@”Hello, World”]; Properties • Readonly • Retain • Readwrite • Copy • Assign Calling Methdos [anObjectsomeMethod]; [anObjectsomeMethod: anotherObject]; [anObjectsomeMethod: anotherObjectwithAnotherArgument: yetAnotherObject] Sending Messages • Objective-C 에서는 해당 객체에 메시지를 보낸다라고 표현한다. • 객체에 메시지를 보내면 해당 메소드를 불러주는 구조 • Receiver may be nil(null) Memory Management • C used methods like malloc and free • C++ used methods like new and delete • Objective-C uses retain pool • Garbage Collection on the Mac, but not on the iPhone Creating Objects NSString *string = [[NSStringalloc] init]; -> You are responsible for releasing the memory NSString *string = [NSStringstringWithString:@”Hello”]; -> The object will be autoreleased. Reference Counting • An Object knows how many times it is referenced • Manually managed or through the autorelease pool • As soon as it falls to 0, the destructor dealloc is automatically called alloc-retain-release alloc +1 retain +1 release -1 release -1 Memory Management • NSString *name = [[NSStringalloc] init]; • [name retain]; • [name release]; • [name autorelease]; Obj-C Vs C++ Obj-C vs C++ Obj-C vs C++ Obj-C vs C++ Obj-C vs C++ Obj-C vs C++ Obj-C vs C++ Design Pattern MVC View Model Controller MVC • Model • 모델은 앱 상태(및 데이터)를 관리하며, 데이터 영속성을 제공하기도 한다. 이것은 완전히 UI와는 분리되어 있으며 사용자에게 직접 드러나지 않는 부분이다. MVC View • 사용자가 실제로 보는 부분이며, 사용자에게 모델을 보여준다. 뷰를 통해서 사용자가 데이터를 변경하도록 하며 이벤트를 생성하게 하거나 이벤트에 응답하도록 한다. 인터페이스 빌더 또는 프로그램 코드에 의해서 생성할 수 있다. MVC • Controller • 사용자 입력 때문에 데이터가 변경되거나 데이터가 변경되어 사용자에게 변경된 데이터를 보여주려고 할 때, 뷰와 모델을 연결 및 중재하는 역할을 한다. 이 컨트롤러에서 앱의 처리 논리를 구현한다. Delegation • 다른 객체를 대신해서 책임지고 어떠한 일을 해주는 클래스 UIAccelerometerDelegate (the delegator) Moving MainController (the delegate) Delegation • Control passed to delegate objects to perform application specific behavior • Avoids need to subclass complex objects • Many UIKit classes use delegates Target-Action • Button Touch – Message send App Dev Cycle Development Cycle Submit Idea Develop Check Prototype Create a Mockup http://iphonemockup.lkmc.ch Prototype Coding 1 Vs N Resources • Images • Sounds • Strings • Database Test • DogFooding • Friend • ….. Distribution Upload Upload Questions?