43
Swift 도입기 Static Library에서 Dynamic Framework전환

D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

Embed Size (px)

Citation preview

Page 1: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

Swift 도입기

Static Library에서 Dynamic Framework로 전환

Page 2: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)
Page 3: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)
Page 4: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)
Page 5: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

WWDC 2014, Swift 등장

Page 6: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

iOS 개발자 반응은?

Page 7: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

WWDC 2015

Page 8: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

대세 언어, Swift!

Page 9: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

2014 20162015

Page 10: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

대세 언어, Swift 도전!

Page 11: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

Objective-C 로 되어 있는 Legacy Code는 어떻게 하지?

Swift 와 Objective-C 함께 사용할 수 있을까?

Page 12: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)
Page 13: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

그리고 열심히 공부하면서 Swift로 개발하기 시작하였습니다.

Page 14: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

var width = selected?320:200

NSUInteger width = selected?320:200;# Objective-C

# Swift

var width = selected ? 320:200

var width = selected?320:200

Page 15: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

헛, 근데 우리는 Library 잖아.

Page 16: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

CocoaPods 로 배포하던 SmartEditor 3.0

Swift 도입 후, 수많은 빨간색 느낌표를 만나게 되다.

Page 17: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

Library

• a set of routines, external functions and variables

• static library (statically-linked library)

• dynamic library (shared library)

• frameworks (static, dynamic)

Page 18: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

static library

• packaged into the code of the main executable

• linked at compile time

• only code

• images/assets/header files은 따로 배포

• 같은 Library 일지라도 실행파일별로 메모리에 로드

Page 19: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)
Page 20: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

dynamic library

• linked at runtime

• shared amongst multiple processes

• OS X :".dylib"

• Windows : ".dll"

• iOS에서는 일반적으로 지원하지 않는다.

Page 21: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)
Page 22: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

Apple은 왜 dynamic library를 iOS에서 금지시켰을까?

The reason is security.

Page 23: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

• malicious code executing by a hacker

• unapproved features to an approved app.

• you could download and load it.

Page 24: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

It's not a technical limitation,

but an App Store Policy limitation.

Page 25: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

Frameworks

• a collection of code and resources to encapsulate functionality

• Libraries only has executable code

• a framework is a bundle (Directory structure)

• dynamic libraries, headers and other resources.

Page 26: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)
Page 27: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

(static) Frameworks

• Before iOS8, only allowed static libraries for iOS.

• the idea of creating 'static frameworks'.

• static libraries with the convenience of bundling the headers files along.

Page 28: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

"iOS developers can now create dynamic frameworks."

- New Features in Xcode 6, by Apple

Page 29: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)
Page 30: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

SmartEditor 3.0 for iOS

CocoaPods 로 배포 중

Page 31: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

• static library 로 빌드하여 배포

• 리소스는 Main Bundle 에 복사

Page 32: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

Swift를 포함한 코드는 static library 로 빌드가 불가능

Page 33: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

• Swift standard runtime libraries 가 iOS에 비포함.

• App 빌드시점에 App Bundle에 runtime library를 복사

• Swift를 포함한 앱은 Objective-C Only 앱보다 용량이 큰 이유

• runtime library가 없거나 버전이 다르면 Swift 를 포함한 Framworks는 문제가 발생

Page 34: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)
Page 35: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

- CocoaPods 0.36 - Framework and Swift Support

"frameworks instead of static libraries by specifying use_frameworks!"

Page 36: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

Podfile

Page 37: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

use_frameworks! 그후

1. Frameworks 로 전환이 안되는 다른 dependency 가 존재

• 네이버로그인 • ApiGatewayHMAC

2. 리소스가 모두 Framework Bundle에 존재

Page 38: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

네이버로그인 라이브러리

• static library를 포함하여 배포 중으로 frameworks로 전환이 불가능

• 서비스앱 (블로그, 포스트) 프로젝트에 수작업으로 static Library와 UI코드/리소스를 추가

• SmartEditor 3.0에서는 delegate를 통해 로그인 모듈 접근

Page 39: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

Frameworks Bundle

• SmartEditor 3.0 에 포함되어 있는 리소스는 MainBundle이 아닌 Frameworkd Bundle에 존재

• + (NSBundle *)bundleForClass:(Class)aClass 를 통해 Framework Bundle에 접근

• [UIImage imageNamed:@""] 는 Main Bundle의 리소를 가져오도록 되어 있어 SEImage Class를 새로 만듬.

Page 40: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)
Page 41: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

Static Library Linking

Page 42: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

Dynamic Library Linking

Page 43: D2 OPEN SEMINAR - Smart editor 3.0 swift 도입기 (static library에서 dynamic framework로 전환)

감 사 합 니 다.