AVPlayer, AVPlayItem
ยท
๐ŸŽ iOS/UIkit
AVPlayer ๋ฏธ๋””์–ด Player์˜ ์ „์†ก ๋™์ž‘์„ ์ œ์–ดํ•˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•˜๋Š” ๊ฐ์ฒด. ์‰ฝ๊ฒŒ๋งํ•˜๋ฉด .. ์žฌ์ƒ ํ”Œ๋ ˆ์ด์–ด์˜ ๋™์ž‘์— ๊ด€ํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•ด์ฃผ๋Š” ๊ฐ์ฒด์ธ๋“ฏ AVAsset์˜ ์ „๋ฐ˜์ ์ธ playback(๋…น์Œ, ๋…นํ™”, ์žฌ์ƒ)์„ ์ œ์–ดํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ์ฒด ๊ตฌ์กฐ AVPlayer๋Š” ํ•œ ๋ฒˆ์— ํ•˜๋‚˜๋งŒ ์žฌ์ƒ์ด ๊ฐ€๋Šฅํ•˜๋ฏ€๋กœ, ์—ฌ๋Ÿฌ ๋ฏธ๋””์–ด๋ฅผ ์žฌ์ƒํ•˜๊ณ  ์‹ถ์œผ๋ฉด AVQueuePlayer ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉ AVPlayerItem ๋ฏธ๋””์–ด ํ”Œ๋ ˆ์ด์–ด์— ๋Œ€ํ•œ ์‹œ๊ฐ„๊ณผ ์ƒํƒœ์ •๋ณด๋ฅผ ๊ฐ–๊ณ  ์žˆ๋Š” ๊ฐ์ฒด. AVAsset: ์ •์ ์ธ ์ƒํƒœ๊ด€๋ฆฌ (์ด ์žฌ์ƒ์‹œ๊ฐ„, ์ƒ์„ฑ๋‚ ์งœ) AVPlayerItem: ๋™์ ์ธ ์ƒํƒœ๊ด€๋ฆฌ (presentation state, ํ˜„์žฌ์‹œ๊ฐ„, ํ˜„์žฌ๊นŒ์ง€ ์žฌ์ƒ๋œ ์‹œ๊ฐ„ ๋“ฑ) ๊ตฌ์กฐ AVPlayerItem ๋‚ด๋ถ€์˜ AVPlayerItemTrack ๊ฐ์ฒด๋ฅผ ํ†ต..
AVFoundation
ยท
๐ŸŽ iOS/UIkit
AVFoundation ์‹œ๊ฐ„์— ๋”ฐ๋ฅธ ์‹œ์ฒญ๊ฐ ๋ฏธ๋””์–ด ์žฌ์ƒ, ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋„์™€์ฃผ๋Š” ํ”„๋ ˆ์ž„ ์›Œํฌ Objective-c ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•ด์ค˜์„œ ๋ฏธ๋””์–ด์— ๋Œ€ํ•œ ์ƒ์„ธํ•œ ์ปจํŠธ๋กค ๊ฐ€๋Šฅ ๋ฏธ๋””์–ดํŒŒ์ผ ๊ฒ€์‚ฌ, ์ƒ์„ฑ, ํŽธ์ง‘, ์žฌ์ธ์ฝ”๋”ฉ ๊ฐ€๋Šฅ ์‹ค์‹œ๊ฐ„์บก์ฒ˜ ๊ฐ€๋Šฅ ์žฌ์ƒ ์ค‘ ์ž…๋ ฅ Stream์„ ๊ฐ€์ ธ์™€์„œ ๋น„๋””์˜ค ์ปจํŠธ๋กค ๊ฐ€๋Šฅ AVFoundation์˜ ์•„ํ‚คํ…์ฒ˜ AVFoundation์€ UIKit๋ณด๋‹ค Core์ชฝ์— ๊ฐ€๊น๊ฒŒ ๋งž๋‹ฟ์•„ ์žˆ๋‹ค. AVFoundation์—์„œ๋Š” ํŠน๋ณ„ํžˆ Audio๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ํด๋ž˜์Šค๊ฐ€ ๋ณ„๋„๋กœ ์กด์žฌํ•œ๋‹ค. (๋‹จ์ˆœ์žฌ์ƒ: AVAudioPlayer, ๋…น์Œ: AVAudioRecorder) AVAsset AVFoundation์—์„œ ๋ฏธ๋””์–ด๋ฅผ ํ‘œํ˜„ํ•ด์ฃผ๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. AVAsset: url์„ ๋ฏธ๋””์–ด๋กœ ๊ฐ์ฒดํ™” ํ•œ๋‹ค. AVAsset์— ์žˆ๋Š” ๋ฏธ๋””์–ด..
SwiftLint ์„ค์น˜ํ•˜๊ณ  ์ ์šฉํ•˜๊ธฐ
ยท
๐ŸŽ iOS/UIkit
SwiftLint Xcode์—์„œ ์ฝ”๋”ฉ ์ปจ๋ฒค์…˜ ๊ด€๋ จ ๊ทœ์น™์„ ์ •ํ•˜๊ณ  ๊ทœ์น™์— ์–ด๊ธ‹๋‚˜๋Š” ๊ฒƒ์ด ์žˆ์œผ๋ฉด ๊ฒฝ๊ณ ์ฐฝ์„ ๋„์›Œ์ฃผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜๋ฐฉ๋ฒ• 1. SwiftLint ์„ค์น˜ brew๋กœ ์„ค์น˜ํ•ด๋ณด๊ฒ ๋‹ค. ํ•ด๋‹น ํด๋”๋กœ ๊ฐ€์„œ brew install swiftlint ์ž…๋ ฅํ•œ๋‹ค. 2. Run Script ์„ค์ • Targets > ํ”„๋กœ์ ํŠธ ํด๋” > ์ƒ๋‹จ์˜ Build Phases > + ๋ฒ„ํŠผ > New Run Script Phase > Run Script์— ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ๋ณต๋ถ™ํ•œ๋‹ค. brew path์— ์œ„์น˜ํ•œ SwiftLint๋ฅผ ์ฐพ์•„๊ฐ€๋„๋ก ํ•˜๋Š” Script๋‹ค. ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ •ํ•˜๋Š”๊ฑฐ๋ž‘ ๋น„์Šทํ•˜๋‹ค. if test -d "/opt/homebrew/bin/"; then PATH="/opt/homebrew/bin/:${PATH}" fi export P..
[UIkit] Alert
ยท
๐ŸŽ iOS/UIkit
func popUp() { let alert = UIAlertController(title: "์•Œ๋ฆผ์ฐฝ์ด๋ฆ„", message: "์•Œ๋ฆผ์ฐฝ ๋ฉ”์‹œ์ง€", preferredStyle: .alert) let success = UIAlertAction(title: "ํ™•์ธ", style: .default) { action in print("ํ™•์ธ๋ฒ„ํŠผ์ด ๋ˆŒ๋ ธ์Šต๋‹ˆ๋‹ค.") } let cancel = UIAlertAction(title: "์ทจ์†Œ", style: .cancel) { cancel in print("์ทจ์†Œ๋ฒ„ํŠผ์ด ๋ˆŒ๋ ธ์Šต๋‹ˆ๋‹ค.") } alert.addAction(success) alert.addAction(cancel) present(alert, animated: true) { print("์™„๋ฃŒ๋˜์—ˆ์Œ") } }
UIView์˜ Drawing Cycle
ยท
๐ŸŽ iOS/UIkit
RunLoop ๋ทฐ์˜ ์—…๋ฐ์ดํŠธ๋ฅผ ๊ด€๋ฆฌํ•˜๋ฉฐ ๊ณ„์† ๋ฐ˜๋ณตํ•ด์„œ ์‹คํ–‰๋œ๋‹ค. Update Cycle 1/60์ดˆ์˜ ์ฃผ๊ธฐ๋งˆ๋‹ค ํ™”๋ฉด์„ ๋‹ค์‹œ ๊ทธ๋ ค์ค€๋‹ค. Layout, Display, Constraints๋ฅผ ์—…๋ฐ์ดํŠธ ํ•œ๋‹ค. Main Run Loop ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ณ  ์ ์ ˆํ•œ ์‘๋‹ต์„ ํŠธ๋ฆฌ๊ฑฐํ•œ๋‹ค. Main Run Loop์˜ ๋งˆ์ง€๋ง‰ ๋‹จ๊ณ„์—์„œ๋Š” Update Cycle์ด ๋ฐœ์ƒํ•œ๋‹ค. Drawing Cycle 1. ์•ฑ์ด ์‹œ์ž‘๋ ๋•Œ ์•ฑ์„ ๋‹ด๋‹นํ•˜๋Š” Main Run Loop๊ฐ€ ์ƒ๊ธฐ๊ณ  2. Main Run Loop๋Š” ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ณ  ์‘๋‹ต์„ ํŠธ๋ฆฌ๊ฑฐํ•œ๋‹ค. 3. Main Run Loop์˜ ๋งˆ์ง€๋ง‰ ๋‹จ๊ณ„์— Update Cycle์ด ๋ฐœ์ƒํ•˜์—ฌ ํ™”๋ฉด์ด ๋‹ค์‹œ ๊ทธ๋ ค์ง„๋‹ค. (ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๋ทฐ๋ฅผ ์ „์ฒด์ ์œผ๋กœ ๋‹ค์‹œ ๊ทธ๋ฆผ) Update cycl..
App Lifecycle
ยท
๐ŸŽ iOS/UIkit
์•ฑ์˜ ์ƒ๋ช…์ฃผ๊ธฐ๋ฅผ ๊ณต๋ถ€ํ•˜๋Š” ์ด์œ  ์•ฑ์˜ ๋น„ํ™œ์„ฑํ™”, ๋ฐฑ๊ทธ๋ผ์šด๋“œ, ์ข…๋ฃŒ ์‹œ์ ์„ ํŒŒ์•…ํ•˜๊ธฐ ์œ„ํ•ด ๊ณต๋ถ€ํ•œ๋‹ค. iOS13์ดํ›„ iOS13 ์ดํ›„๋ถ€ํ„ฐ๋Š” SceneDelegate.swift์—์„œ ์žฅ๋ฉด ๊ธฐ๋ฐ˜์˜ ์•ฑ์˜ ์ƒ๋ช…์ฃผ๊ธฐ๋ฅผ ๋‹ค๋ฃฌ๋‹ค. SceneDelegate ๋‚ด๋ถ€์˜ ๋ฉ”์„œ๋“œ๋“ค์„ ํ†ตํ•ด ์‹œ์ ์„ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค. Unattached scene์ด ์•„์ง ์—ฐ๊ฒฐ๋˜์ง€ ์•Š์€ ์ƒํƒœ Foreground inactive ์•ฑ์ด foreground์—์„œ ์‹คํ–‰์ค‘์ด์ง€๋งŒ ์•„๋ฌด๋Ÿฐ ์ด๋ฒคํŠธ๋ฅผ ๋ฐ›์ง€ ์•Š๊ณ  ์žˆ๋Š” ์ƒํƒœ Background ์•ฑ์ด Background์— ์žˆ์œผ๋ฉฐ ์‹คํ–‰๋˜๋Š” ์ฝ”๋“œ๊ฐ€ ์žˆ๋Š” ์ƒํƒœ ๋Œ€๋ถ€๋ถ„ ์•ฑ์€ suspended์ƒํƒœ๋กœ ์ดํ–‰ํ•˜๋Š” ๋„์ค‘์— ์ผ์‹œ์ ์œผ๋กœ ์ด ์ƒํƒœ์— ์ง„์ž…ํ•˜์ง€๋งŒ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ, ์—…๋กœ๋“œ ๋“ฑ ํŠน์ • ์‹œ๊ฐ„๋™์•ˆ ์ด ์ƒํƒœ๋กœ ๋‚จ์•„์žˆ๊ฒŒ ๋˜๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๋‹ค. Suspend..
ViewController LifeCycle
ยท
๐ŸŽ iOS/UIkit
์‹œ์ ์„ ์ค‘์‹ฌ์œผ๋กœ ๊ธฐ์–ตํ•ด์•ผํ•œ๋‹ค. viewDidLoad ๋ทฐ๊ฐ€ ์ƒ์„ฑ๋˜์—ˆ์„ ๋•Œ ํ•œ๋ฒˆ๋งŒ ํ˜ธ์ถœ๋˜๋ฉฐ, ์Šคํ† ๋ฆฌ๋ณด๋“œ์ƒ์˜ ๋ทฐ๋“ค๊ณผ ์—ฐ๊ฒฐ์ด ๋๋‚œ ์‹œ์ ์„ ์˜๋ฏธํ•œ๋‹ค. viewWillAppear ๋ทฐ๊ฐ€ ํ™”๋ฉด์— ๋‚˜ํƒ€๋‚ ๋•Œ๋งˆ๋‹ค ๊ณ„์† ํ˜ธ์ถœ๋˜๋ฉฐ, ์‹ค์ œ ์Šคํฌ๋ฆฐ์— ๋ทฐ๊ฐ€ ๋‚˜ํƒ€๋‚˜๊ธฐ ์ „์— ํ˜ธ์ถœ๋œ๋‹ค. viewDidAppear ์‹ค์ œ ์Šคํฌ๋ฆฐ์— ๋ทฐ๊ฐ€ ๋‚˜ํƒ€๋‚œ ํ›„์— ํ˜ธ์ถœ๋œ๋‹ค. viewWillDisAppear ์‹ค์ œ ์Šคํฌ๋ฆฐ์— ๋ทฐ๊ฐ€ ์‚ฌ๋ผ์ง€๊ธฐ ์ „์— ํ˜ธ์ถœ๋œ๋‹ค. viewDidDisappear ์‹ค์ œ ์Šคํฌ๋ฆฐ์— ๋ทฐ๊ฐ€ ์‚ฌ๋ผ์ง„ ํ›„์— ํ˜ธ์ถœ๋œ๋‹ค. ๋ฉ”๋ชจ๋ฆฌ์—์„œ ์—†์–ด์ง„ ๊ฒƒ์€ ์•„๋‹ˆ๋‹ค.
JerryiOS
'๐ŸŽ iOS/UIkit' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก