57
let swift(16) 스위프트 개발 환경의 변화 Interface Builder, Xcode, LLDB , Instrument OSXDEV.org 허혁

Swift and Xcode8

Embed Size (px)

Citation preview

Page 1: Swift and Xcode8

let swift(16)

스위프트�개발�환경의�변화Interface Builder, Xcode, LLDB, Instrument

OSXDEV.org허�혁

Page 2: Swift and Xcode8

let swift(16)

Swift3?

Page 3: Swift and Xcode8

New APIs

iOS10?�iOS9?�내년에나�써볼�수�있어요.�

그런데������������������������������������������������������������������������������������������������������������������������������������������������������������������������

New�iOS는�New�SDK로�

New�SDK는�New�Xcode로�

Xcode는�우리가�당장�쓸�수�있는�것.

Page 4: Swift and Xcode8

Agenda

Interface Builder

Source Editing

Sanitizers

View Debugging

LLDB

Instrument

Summary

Page 5: Swift and Xcode8

let swift(16)

Interface Builder

Page 6: Swift and Xcode8

Interface Builder

새로운 Adaptive UI - 디바이스�타입별�렌더링�

Live preview - 디바이스�타입별

수정�하면서도�확대�축소

Page 7: Swift and Xcode8
Page 8: Swift and Xcode8
Page 9: Swift and Xcode8
Page 10: Swift and Xcode8

let swift(16)

Source Editing

Page 11: Swift and Xcode8

Source Editing

Xcode Source Editor Extension

드디어�확장�환경�제공�

안전해�

벌써�만들어�본�사람들�

알카트라즈�플러그인�개발자들은�패닉�

번들�로딩�금지�

잘�쓰던�나도�패닉

Page 12: Swift and Xcode8

Source Editing

새로와진�API�문서�

오프라인�API�문서�

API�문서�자동생성�

SF Mono Font

Code-signing, Provision

Page 13: Swift and Xcode8

Source Editing

Page 14: Swift and Xcode8

Source Editing

Page 15: Swift and Xcode8

Source Editing

현재�라인�하이라이트

Color Literal

#colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)

Page 16: Swift and Xcode8

Source Editing

현재�라인�하이라이트

Color Literal

#colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)

Page 17: Swift and Xcode8

Image Literal

UIImage(#imageLiteral(resourceName: "Screen Shot"))

Source Editing

Page 18: Swift and Xcode8

Image Literal

UIImage(#imageLiteral(resourceName: "Screen Shot"))

Source Editing

Page 19: Swift and Xcode8

let swift(16)

Sanitizers

Page 20: Swift and Xcode8

Sanitizers?

Page 21: Swift and Xcode8

Sanitizers

런타임�시�버그�추적�

Swift3 / C/C++/Objective-C

컴파일�시�버그�추적은?�

Clang Static Analyzer

C/C++/Objective-C�만�지원

Page 22: Swift and Xcode8

Sanitizers Types

AddressSanitizer - ASan

ThreadSanitizer - TSan

MemorySanitizer - MSan (LLVM)

Page 23: Swift and Xcode8

Sanitizers Types

AddressSanitizer - ASan

ThreadSanitizer - TSan

Memory Graph Debugging

Page 24: Swift and Xcode8

AddressSanitizer

디버깅�모드로�동작할�때�잠재적인�메모리�누수를�찾는다�

메모리�어드레스�오염�이슈를�찾는다�

이제 Swift도�지원

설정; Scheme의 Diagnostics항목

Enable Address Sanitizer

Page 25: Swift and Xcode8

디버깅�모드로�동작할�때�잠재적인�메모리�누수를�찾는다�

메모리�어드레스�오염�이슈를�찾는다�

이제 Swift도�지원

설정; Scheme의 Diagnostics항목

Enable Address Sanitizer

AddressSanitizer

Page 26: Swift and Xcode8

AddressSanitizer

검출�케이스�

힙,�스팩,�글로벌�버퍼�오버�플로우�

메모리�반환�후�사용�

return 후�사용�

메모리�릭

Page 27: Swift and Xcode8

런타임�시�쓰레드에�의한�데이터�변경에�레이스�컨디션이�발생했는지를�알아낸다.�

설정; Scheme의 Diagnostics항목

Enable Thread Sanitizer

지원범위�

64비트 macOS, iOS 시뮬레이터, tvOS 시뮬레이터

watchOS와 Device는�아직�미지원

ThreadSanitizer

Page 28: Swift and Xcode8

런타임�시�쓰레드에�의한�데이터�변경에�레이스�컨디션이�발생했는지를�알아낸다.�

설정; Scheme의 Diagnostics항목

Enable Thread Sanitizer

지원범위�

64비트 macOS, iOS 시뮬레이터, tvOS 시뮬레이터

watchOS와 Device는�아직�미지원

ThreadSanitizer

Page 29: Swift and Xcode8

테스트�돌릴�때�옵션을�키기를�추천�

검출�케이스�

초기화�되지�않은�뮤텍스�사용�

엉뚱한�쓰레드가�언락�

쓰레드�릭�

시그널�핸들러에�안전하지�않은�함수�호출�

데이터�레이스

ThreadSanitizer

Page 30: Swift and Xcode8

데이터�레이스�

동기화�없이�여러�쓰레드가�한�주소를�접근할�때�

그�중�하나는�읽기용�쓰레드�

끝난다면�결국�쓰레기�값이나�메모리�오염으로�

구조상�문제가�있다는�것�

혹은�동기화�작업�누락

ThreadSanitizer

Page 31: Swift and Xcode8

Memory Graph Debugging

메모리�누수나�버려진�메모리�탐침�

디버깅�모드에서 pause된�경우

macOS, iOS 10, tvOS 10, watchOS 3 지원

Sanitizer가�켜져�있으면�동작�안함

Scheme의 Diagnostics 탭에서 Malloc Stack설정

All Allocation

Live Allocation Only

Page 32: Swift and Xcode8

메모리�누수나�버려진�메모리�탐침�

디버깅�모드에서 pause된�경우

macOS, iOS 10, tvOS 10, watchOS 3 지원

Sanitizer가�켜져�있으면�동작�안함

Scheme의 Diagnostics 탭에서 Malloc Stack설정

All Allocation

Live Allocation Only

Memory Graph Debugging

Page 33: Swift and Xcode8

Memory Graph Debugging

두가지�그래프�스타일�

Root Paths

참조�메모리�

얼마나�많은�메모리가�잡혀�있는지�

Cycles

메모리�누수�

누수가�어떻게�다른�누수와�연결되는지

Page 34: Swift and Xcode8
Page 35: Swift and Xcode8

Memory Graph Debugging

.memgraph; Plist file

저장하기�

File → Export Memory Graph

불러오기�

Open the file

디버거�프로세스가�아니라서�트레이스,�퀵룩,�po�안됨;�그래프�말고는�아무것도�안됨

Page 36: Swift and Xcode8

let swift(16)

View Debugging

Page 37: Swift and Xcode8
Page 38: Swift and Xcode8
Page 39: Swift and Xcode8

View Debugging

빨라지고�정확해짐�

클래스로�바로가기�

네비게이터에서�필터링�

오토레이아웃�디버깅

Page 40: Swift and Xcode8

View Debugging

클래스로�바로가기

Page 41: Swift and Xcode8

View Debugging

네비게이터에서�필터링

Page 42: Swift and Xcode8

View Debugging

오토레이아웃�디버깅

Page 43: Swift and Xcode8

View Debugging

오토레이아웃�디버깅

Page 44: Swift and Xcode8

View Debugging

유한�상태�머신�Quick Look

GKStateMachine; GameplayKit를�써야…�

코드로는�알아보기�힘듬�

복잡한�동작을�그래프로�직관적으로�정의�가능�

상태별�개별�동작�

상태간�전환

Page 45: Swift and Xcode8

유한�상태�머신�Quick Look

GKStateMachine; GameplayKit를�써야…�

코드로는�알아보기�힘듬�

복잡한�동작을�그래프로�직관적으로�정의�가능�

상태별�개별�동작�

상태간�전환

View Debugging

Page 46: Swift and Xcode8

let swift(16)

LLDB

Page 47: Swift and Xcode8

LLDB

스위프트 REPL도 LLDB

:<command> enables any LLDB command

Page 48: Swift and Xcode8

LLDB

Xcode와 LLDB는�별도�프로세스로�분리�

LLDB는�죽어도 Xcode는�적당히�살아난다�

여러�버전의�디버거�지원�

디버거는�자동적�선택됨�

예를�들면 Swift 3는�가장�최신�디버거�

Swift 2.3는 Xcode 7.3.1-era 디버거

오픈소스 Swift도�매칭된�디버거를�사용하게�된다

Page 49: Swift and Xcode8

LLDB

parray <count> <expression>

poarray <count> <expression>

자동 import

@import UIKit

settings show target.auto-import-clang-modules false

Debugger Customization

Page 50: Swift and Xcode8

LLDB

Reusable Code $

expr let a = 3; print(a)

expr $addTwoNumbers(a: 2, b: 3)

Page 51: Swift and Xcode8

let swift(16)

Instrument

Page 52: Swift and Xcode8

Instrument

디버깅�시�정보�표시가�더�잘보여요.�

시스템�트레이스�

쓰레드, CPU, Point of Interest

타임�프로파일러�

앱�라이프�사이클�이벤트에�따른�동작�

메탈�시스템�트레이스…�?

Page 53: Swift and Xcode8

let swift(16)

Demo

Page 54: Swift and Xcode8

Demo

시간�관계�상�생략?�

개별�연락?�

샘플�프로젝트?

Page 55: Swift and Xcode8

Summary

Interface Builder 👍

Source Editing 👍

Sanitizers 👍

LLDB 👍

Instrument 🖖

Page 56: Swift and Xcode8

let swift(16)