Upload
val
View
72
Download
0
Embed Size (px)
DESCRIPTION
iOS Development Seminar. [email protected] 정 창제 2 013 06. iOS. Apple 의 mobile OS iPhoneOS3 -> iOS4 iPhone, iPad, iPod touch iOS61.3 Objective-C 2.0 Mac OS & XCode4 필요 오직 AppStore 만 존재 승인되지 않은 앱은 설치할 수 없다. iOS Developer Program. iOS SDK 는 무료로 이용가능 - PowerPoint PPT Presentation
Citation preview
iOS
Apple 의 mobile OS
iPhoneOS3 -> iOS4
iPhone, iPad, iPod touch
iOS61.3
Objective-C 2.0
Mac OS & XCode4 필요
오직 AppStore 만 존재
승인되지 않은 앱은 설치할 수 없다
iOS Developer Program iOS SDK 는 무료로 이용가능
하지만 App 의 Device Test, 배포 , APNS, iCloud, 개발지원의 이용을 위해서는 유료 계정이 필요
공부를 위해서는 훌륭한 Simulator 로도 충분
개인개발자 $99, 기업용개발 $299 per year
http://developer.apple.com/ios
iOS Developer Library
iOS 는 문서화가 굉장히 잘 되어 있다 .
http://developer.apple.com/library/ios
Objective-C 2.0
Tutorial : Start Developing iOS Apps Todayhttps://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/chapters/WriteObjective-CCode/WriteObjective-CCode/
WriteObjective-CCode.html
Objective-C 2.0
C 를 기반으로 Smalltalk Style 의 메시지 방식을 추가한 OOP 언어
Next 사의 NeXTSTEP 에서 사용되었고 후에 애플이 Next를 인수하여 Mac OS X 을 제작할 때 NeXTSTEP 이 기반이 되었기 때문에 애플의 Cocoa Framework 의 사용 언어
Objective-C 2.0 은 애플이 1.0 에서 개선한 버전
Objective-C 2.0
C 언어와 엄격한 하위호환성을 가진다
JAVA 의 interface 와 같은 Protocol 지원 , 다중상속불가
Method 호출이 아닌 , Message 전달 방식이 기본 철학
MVC 모델
Garbage Collector 기능 (ARC,Auto Reference Count) 이 지원되나 iOS 에서는 5.0 이상부터 이용가능
파일구조
.h : Header file. class,type,function,constant declaration
.m : Implementation file. Objective-C & C code.
.mm : Implementation file. Objective-C & C++ Code.
대표적자료형
C 의 모든 자료형
NSNumber, NSInteger, NSDouble...
NSString
NSDictionary,NSSet,NSArray,...
NSURL,NSURLRequest,NSURLResponse…
대표적자료형
Objective-C 에서는 String 을 @”” 로 감싼다
@”asdfasdf”
iOS 6.0 이후부터 다음의 Syntax 도 지원한다 .
@"42” //[NSNumber numberWithInt:42];
@[@"a",@"b”] //[NSArray arrayWithObjects:@”a”,@”b”,nil];
@{@"key1":@"value1",@"key2":@"value2”}
클래스 선언 (.h)
클래스 선언 (.h)
@interface classname : superclassname <Protocol1,Protocol2>{ // 클래스 변수}+ classMethod1; // 클래스 메소드+ (return_type)classMethod2;+ (return_type)classMethod3:(param1_type)param1_varName; - (return_type)instanceMethod1:(param1_type)param1_varName :(param2_type)param2_varName; // 인스턴스 메소드- (return_type)instanceMethod2WithParameter:(param1_type)param1_varName andOtherParameter:(param2_type)param2_varName;@end
클래스 구현 (.m) #import “MyClass.h”
@implementation MyClass+ (return_type)classMethod{ // Implementation..}- (return_type)instanceMethod{ // Implementation..}@end
포인터
Static typing MyClass *myObject1; // MyClass 포인터로 object 를 지정
Dynamic typing id myObject2; // id 포인터 (void 포인터 ) 로 object 를 지정 id 는 특별한 포인터로 아무 Object 나 가르킬 수 있다 .
메시지 패싱
메시지 패싱
[Object method:message];
[NSString stringWithFormat:@"%@",@"rodumani"];
[webView loadRequest:[[NSURLRequest alloc]initWithURL:
[[NSURL alloc]initWithString:@"http://m.naver.com"]]];
NSURLRequest *request1 = [webView request];
NSURLRequest *request2 = webView.request;
Property
In the general sense, property is some data encapsulated or stored by an object. It is either an attribute—such as a name or a color—or a relationship to one or more other objects.
Property 는 setPropertyName, propertyName 의 setter, getter 가 자동 생성되며 , dot notation 을 통한 접근이 된다 .
Property 에는 getter, setter 의 동작에 대한 Option 을 줄 수 있다 .
Accessor 들은 Cocoa,Cocoa Touch Framework 에서 KVC 등을 쓸수 있게 해주는 중요한 Element 이다 .
Property Options
@property (nonatomic, copy) NSString *userName;
nonatomic / atomic :
atomic 을 설정하면 , Accessor Methods 에 lock 을 사용하여 Multi Thread 에 안전하게 처리한다 . 대부분 고려하지 않아도 되는 변수들 이기 때문에 nonatomic 으로 해줘서 성능을 향상시킨다 . 기본값은 atomic 이다 .
assign / copy / retain :
Value 를 Copy 해서 return 하거나 그 자체의 value 를 return 한다 . Retian 의 경우 대입연산을 할 때마다 Reference Count 가 증가한다 . assign 은 setter 가 받은 값을 그대로 대입하는 행동을 한다 .
readwrite / readonly :
readonly 는 setter 가 없다 .
Protocol
Protocol 이란 , Protocol 을 준수하는 Object 는 Protocol 에 선언된 함수를 실행함을 보장하며 , 그 함수들을 이용한 작동을 한다는 뜻이다 .
iOS 에서 Delegate Pattern 은 매우 자주 사용되는 Pattern으로 Object 가 적절한 행동을 취한 뒤 , Delegate( 위임자 )에게 나머지 행동을 맡기는 것이다 .
나머지 행동으로 필요한 것을 대부분 Protocol 에서 정의한다 .
@interface HelloWorldViewController : UIViewController <UITextFieldDelegate>
Delegate Pattern :http://en.wikipedia.org/wiki/Delegation_pattern
Category
상속 없이 클래스를 확장하는 방법
기존 클래스에 내가 추가로 생성한 Method 를 넣을 수 있다 .
Start Developing iOS App Today• iOS 앱 개발 시작을 설명하는 애플에서 작성한 문서
• http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/index.html%23//apple_ref/doc/uid/TP40011343
iOS MVC Model
*.h, *.m : ViewController 혹은 DataSource 의 Source Code
*.storyboard, *.xib : MVC 모델에서 V 에 해당하는 Layout 을 정의하는 파일 . (android layout xml)
storyboard 는 Action 에 따른 화면의 전환을 구성할 수 있는 진보된 Layout 구성 방법이다 . (XCode 4.3 이상 , iOS5 이상요구 )
storyboard : http://pinkyroman.tistory.com/4
이 세미나에서 앞으로 사용할 환경
Mac OS X 10.8 Mountain Lion 기준
Xcode 4.6.2
iOS 6.1.3
Deployment Target 6.0
Hello World!
Xcode 를 켜고 Create a new Xcode project 혹은 상단 메뉴바의 File-New-Project
iOS – Application – Single View Application
Product name : helloworld
Organization name : SPARCS
Company Identifier : org.SPARCS.
Class Prefix : Empty
Devices : iPhone
Use Automatic Reference Counting
StoryBoard 는 사용안함
더블클릭 !
iOS Simulator
A 당의 에뮬레이터와는 비교되지 않는 속도와 정확히 1:1대응되는 작동
Hardware-Device 에서 디바이스 종류를 선택 가능
Hardware – Lock(⌘L), Home(⌘- Shift – H) 등의 홈버튼과 Lock 도 지원
멀티테스킹 테스트도 가능
Option 키를 누르면 핀치줌 테스트 ( 화면 중심이 기준 )
단 , iCloud, APNS 등의 하드웨어 의존적인 기능은 테스트 불가
곱셈 계산기
1. UI 작성
View 와 Code 의 연결
버튼이 눌려지면 불리울 함수#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *lhsTextField;
@property (strong, nonatomic) IBOutlet UITextField *rhsTextField;
@property (strong, nonatomic) IBOutlet UIButton *calculateButton;
@property (strong, nonatomic) IBOutlet UILabel *resultLabel;
-(IBAction)calculate:(id)selector;
@end
버튼이 눌려지면 불러올 함수
연결은 마우스로
문제점
키보드가 안내려간다…
입력해도 의미없는 알파벳 키보드가 뜬다
개선점
Calculate 눌렀을 때 키보드를 내리자
화면을 눌렀을 때도 키보드를 내리자
키보드는 숫자키패드로 변경
키보드를 내리는 함수
1. calculate 를 눌렀을 때 키보드 내리기
2. 화면을 눌렀을 때 키보드 내리기
3. Number Keyboard 로 바꾸기
완성 !
다음시간
음…… 안되면 세미나 자료만이라도 돌릴께요
UITableView & UINavigationController 사용하기
HTTP NetworkRequest
JSON
기타 등등