Upload
others
View
0
Download
0
Embed Size (px)
Citation preview
Chapter 00. 강의 소개
Chapter 01. Mobile Application
Chapter 02. 기본 프로그래밍
강의 내용 최근 큰 인기를 끌고 있는 Mobile Application에 관한 소개 및 실제 이를 위한 개발 방법을 소개하며, Application 개발에 관한 프로그래밍을 간략히 진행
강의 목표 - 프로그래밍의 기본 흐름 이해
- 창의 SW 설계에서 프로그래밍을 이용한 프로젝트 진행에 도움을 주기 위함
강사 소개 - 정명범 : 010-6771-1061, [email protected]
Mobile Application = 모바일 응용 소프트웨어 스마트 폰, 태블릿 PC 등 Mobile에서 실행되는 응용 소프트웨어
- 구글 플레이 : 안드로이드 앱, App Store : 아이폰 앱
Mobile Application 분류 (Apple Store 기준) 건강 및 피트니스, 게임, 금융, 교육, 날씨, 내비게이션, 뉴스, 도서, 라이프스타일, 비즈니스, 사진 및 비디오, 생산성, 쇼핑, 소셜네트워킹, 스포츠, 어린이, 엔터테인먼트, 여행, 유틸리티, 음식 및 음료, 음악, 의학, 잡지 및 신문, 참고, 카탈로그
사용 기술에 따른 분류
Data 저장소에 따른 분류
Local Data 사용
Network Data 사용
Sensor 사용에 따른 분류*
Ambient light, Proximity, Dual Cameras, GPS, Accelerometer
Dual microphones, Compass, Gyroscope 등
* A Survey of Mobile Phone Sensing
Android
Java 언어, Windows & Mac에서 개발
eclipse
JDK
Android SDK
iOS
Objective C & Swift 언어, Mac에서 개발
Xcode
- Class Level -
20: beginner level 10: medium 6: upper medium 4: no experience
Objective C
아이폰과 맥 os x 개발을 위한 objective-c 2.0
프로그래밍의 기본을 익힘
객체 지향 언어
Class, 상속, 컴포지션, 소스 파일 구성 등
Application 개발 방법 소개
윈도우에서 Objective C 프로그래밍을 하기 위한 웹 http://www.tutorialspoint.com/compile_objective-c_online.php
윈도우에서 Objective C 프로그래밍을 하기 위한 Dev-C++
http://www.evernote.com/l/Ahjak0K9x0ZAhKHOih64PERT6LLZMWLtAcg/
절차 지향 s
구조체
ShapeRect
Shape
함수
drawShapes
drawCircle
drawRectangle
drawEgg
colorname
Main: 실행
절차 지향
함수
drawShapes
void drawShapes (Shape shapes[], int count) { int i; for (i=0; i<count; i++) { switch (shapes[i].type) { case kCircle: drawCircle (shapes[i].bounds, shapes[i].fillColor); break; case kRectangle: drawRectangle (shapes[i].bounds, shapes[i].fillColor); break; case kOblateSpheroid: drawEgg (shapes[i].bounds, shapes[i].fillColor); break; } } }
void drawShapes (id shapes[], int count) { int i; for (i=0; i<count; i++) { id shape = shapes[i]; [shape draw]; } }
객체 지향
Circle
fillColor bounds
setFillColor: setBounds:
draw
Rectangle
fillColor bounds
setFillColor: setBounds:
draw
OblateSphereoid
fillColor bounds
setFillColor: setBounds:
draw
객체 지향
객체 지향 main 함수 내 코드
id shapes[3]; ShapeRect rect0 = {0,0,10,30}; shapes[0] = [Circle new]; [shapes[0] setFillColor:kRedColor]; [shapes[0] setBounds:rect0]; ShapeRect rect1 = {30,40,50,60}; shapes[1] = [Rectangle new]; [shapes[1] setFillColor:kGreenColor]; [shapes[1] setBounds:rect1]; ShapeRect rect2 = {15,18,37,29}; shapes[2] = [OblateSphereoid new]; [shapes[2] setFillColor:kBlueColor]; [shapes[2] setBounds:rect2]; drawShapes (shapes, 3);
Shape shapes[3]; ShapeRect rect0 = {0,0,10,30}; shapes[0].type = kCircle; shapes[0].fillColor = kRedColor; shapes[0].bounds = rect0; ShapeRect rect1 = {30,40,50,60}; shapes[1].type = kRectangle; shapes[1].fillColor = kGreenColor; shapes[1].bounds = rect1; ShapeRect rect2 = {15,18,37,29}; shapes[2].type = kOblateSpheroid; shapes[2].fillColor = kBlueColor; shapes[2].bounds = rect2; drawShapes (shapes, 3);
상속 s
Circle
fillColor bounds
setFillColor: setBounds:
draw
Rectangle
fillColor bounds
setFillColor: setBounds:
draw
OblateSphereoid
fillColor bounds
setFillColor: setBounds:
draw
Shape
fillColor Bounds
setFillColor: setBounds:
draw
Circle
draw
Rectangle
draw
OblateSphereoid
draw
상속
@interface Shape: NSObject { ShapeColor fillColor; ShapeRect bounds; } - (void) setFillColor: (ShapeColor) fillColor; - (void) setBounds: (ShapeRect) bounds; - (void) draw; @end @implementation Shape - (void) setFillColor:(ShapeColor) c { fillColor = c; } - (void) setBounds:(ShapeRect) b { bounds = b; } - (void) draw { } @end
상속 시 함수의 실행 (1)
상속 시 함수의 실행 (2)
상속 시 함수의 실행 (3) – 슈퍼 클래스의 호출
컴포지션 s
각 컴포넌트를 모아서 더 큰 것을 만드는 작업
Car – 엔진 1개, 바퀴 4개로 구성된 프로그램 자동차 만들기
Engine, Tire, Car 클래스 필요
Car는 Engine 1개, Tire 4개를 갖는 변수 필요함
@interface Tire : NSObject @end @implementation Tire - (NSString *) description { return (@"I am a tire. I last a while"); } @end @interface Engine : NSObject @end @implementation Engine - (NSString *) description { return (@"I am an engine. Vroom!"); } @end
컴포지션 Car, Main
그러나 일반적으로 Car에서 엔진과 타이어를 만드는 것이 아니라, 엔진과 타이어는 Car를 만들 때 생성해서 붙이는 방식이 되어야 함
접근자 메소드
int main(int argc, const char * argv[]) { Car *car; car = [Car new]; Engine *engine = [Engine new]; [car setEngine:engine]; int i; for (i=0; i < 4; i++) { Tire *tire = [Tire new]; [car setTire:tire atIndex:i]; } [car print]; return 0; }
CarParts 확장 : 현재 만든 파일에 구현 실습
Slant 6 (엔진을 상속 받음)
“I am a slant-6. VROOOM!” 출력
AllWeatherRadial (타이어를 상속 받음)
“I am a tire for rain or shine.” 출력
파일 구성
유지 보수를 위해 자동차, 엔진, 타이어에 따른 파일 분리 필요
인터페이스(interface)와 구현(implementation)을 나누어야 함
.h : 인터페이스, .m : 구현
파일 구성 Engine.h, Engine.m
Tire.h, Tire.m
Car.h : 엔진과 타이어를 변수 선언 및 사용 해야 함
#import “Engine.h”
#import “Tire.h”
main.m : 차를 생성해야 하며, 엔진과 타이어 생성함
#import “Car.h”
Car.h에서 Engine과 Tire를 불러왔기 때문에 별도로 추가 안함
추가적으로 Slant 6, AllWeatherRadial도 적용
Foundation Kit 소개
Foundation Kit : 데이터 조작 클래스, 자료 타입
Application Kit : 사용자 인터페이스 객체 (버튼, 이미지 박스 등)
데이터를 조작하기 위해 반드시 필요한 부분
#import <Foundation/Foundation.h>
Foundation Kit 소개
유용한 타입
NSRange (location, length) – NSMakeRange ( )
NSPoint (x, y), NSSize (width, height) - NSMakePoint( ), NSMakeSize( )
NSRect (NSPoint origin, NSSize size) – NSMakeRect( )
문자열 처리 클래스
NSString
NSString *height = [NSString stringWithFormat:@”Height: %d”, 5];
팩토리 메소드: 위와 같이 새 객체를 생성하는데 사용하는 메소드
[height length]; // 위 NSString의 길이를 알아올 때 사용
Foundation Kit 소개
NSString
Foundation Kit 소개
컬렉션
NSArray, NSMutableArray
NSDictionary, NSMutableDictionary
여러가지 값
NSNumber
NSValue
객체 초기화 s
Initialization
초기화를 실행하는 메소드 : init
차를 만들때 기본 엔진, 기본 타이어 만드는 기본 옵션 초기화
많은 클래스들이 편리한 이니셜라이저(initializer)를 가지고 있음
NSString *emptyString = [[NSString alloc] init];
string = [[NSString alloc] initWithFormat: @”%d or %d”, 25, 624];
string = [[NSString alloc] initWithContentsOfFile:@”/tmp/word.txt”];
타이어를 만들 때도 공기압, 마모 상태를 초기화&설정 하는 메소드 구현 가능
타이어 초기화 및 설정 코드
#import <Foundation/Foundation.h> @interface Tire : NSObject { float pressure; float treadDepth; } - (void) setPressure:(float) pressure; - (float) pressure; - (void) setTreadDepth:(float) treadDepth; - (float) treadDepth; @end
타이어를 불러오는 곳(Car.h) 과 실제 사용하는 곳(main.h) 수정
객체 초기화
초기화 하면서 바로 설정하는 편리한 이니셜 라이저 작성
- (id) initWithPressure: (float) pressure treadDepth: (float) treadDepth;
초기화 하면서 타이어 공기압만 설정하는 이니셜 라이저
- (id) initWithPressure: (float) pressure;
초기화 하면서 타이어 마모상태만 설정하는 이니셜 라이저
- (id) initWithTreadDepth: (float) treadDepth;
프로그램 시연