iOS Development Seminar - SPARCS
Download
Report
Transcript iOS Development Seminar - SPARCS
iOS Development Seminar
[email protected]
정 창제
2013 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는 무료로 이용가능
하지만 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 Today
https://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/Getti
ngStarted/RoadMapiOS/index.html%23//apple_ref/doc/uid/TP
40011343
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
기타 등등