728x90
๋ฐ˜์‘ํ˜•
[SwiftUI] re-rendering, re-draw ์ปค์Šคํ„ฐ๋งˆ์ด์ง• (?)

[SwiftUI] re-rendering, re-draw ์ถ”์ธก ์—์„œ SwiftUI๊ฐ€ ๋‚ด๋ถ€์ ์œผ๋กœ ๋ฆฌ๋ Œ๋”๋ง์„ ์–ด๋–ป๊ฒŒ ๊ฒฐ์ •ํ•˜๋Š” ์ง€ ์ถ”์ธกํ•ด๋ณด์•˜๋Š”๋ฐ์š” ๋ฆฌ๋ Œ๋”๋ง์„ ์ปค์Šคํ„ฐ๋งˆ์ด์ง• (?) ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์Šต๋‹ˆ๋‹ค. # 1. SwiftUI ๋Š” ๋‹ค์‹œ ์•ˆ๊ทธ๋ฆฌ๋Š”๋ฐ, ๋‚˜๋Š” ๋‹ค์‹œ ๊ทธ๋ฆฌ๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ ๋ทฐ๋Š” extract subview๋ฅผ ํ•˜๋ฉด ๋ณ„๋„์˜ identity๋ฅผ ๋ถ€์—ฌ๋ฐ›์•„, ๋ถ€๋ชจ ๋ทฐ์™€ ๊ฐ™์ด ๋ฆฌ๋ Œ๋”๋ง์ด ์•ˆ๋ฉ๋‹ˆ๋‹ค. ๋ถ€๋ชจ์˜ body๊ฐ€ ์žฌํ˜ธ์ถœ๋  ๋•Œ extracted ํ•œ ์„œ๋ธŒ๋ทฐ๋ฅผ ํ•ญ์ƒ ๊ฐ™์ด ๋‹ค์‹œ ๊ทธ๋ฆฌ๊ณ  ์‹ถ์œผ๋ฉด id๋ฅผ ํ™œ์šฉํ•ฉ๋‹ˆ๋‹ค. [ ๊ธฐ๋ณธ ๋™์ž‘ ] ContentView์˜ body๊ฐ€ ํ˜ธ์ถœ๋  ๋•Œ NoMatterText๋Š” ๋‹ค์‹œ ์•ˆ๊ทธ๋ ค์ง struct ContentView: View { @State private var isOn = true pri..

๐Ÿ/SwiftUI + Combine 2022. 11. 16. 23:56
[SwiftUI] re-rendering, re-draw ์ถ”์ธก

[ ์ธํŠธ๋กœ ] SwiftUI๋Š” state-driven, data-driven ๋ฐฉ์‹์œผ๋กœ state ๊ฐ€ ๋ณ€ํ•˜๋ฉด view ๋ฅผ ๋‹ค์‹œ ๊ทธ๋ฆฝ๋‹ˆ๋‹ค (body๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ) ํ•˜์ง€๋งŒ body๋ฅผ ์žฌํ˜ธ์ถœํ•œ๋‹ค๊ณ  ๋ชจ๋“  ๊ฒƒ์„ ๋‹ค์‹œ ๊ทธ๋ฆฌ๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๋ณ€๊ฒฝ์ด ํ•„์š”ํ•œ ๋ถ€๋ถ„๋งŒ ๋‹ค์‹œ ๋ Œ๋”๋ง ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด.. re-rendering ๋˜๋Š” re-draw๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” SwiftUI์˜ diff ํŒ๋‹จ ๋กœ์ง์€ ์–ด๋–ป๊ฒŒ ๋ ๊นŒ์š”? (= body๊ฐ€ ํ˜ธ์ถœ๋  ๋•Œ ๋ฌด์—‡์„ ๋‹ค์‹œ ๊ทธ๋ฆฌ๊ณ , ๋ฌด์—‡์„ ๋‹ค์‹œ ์•ˆ๊ทธ๋ฆด ์ง€ ์–ด๋–ป๊ฒŒ ๊ฒฐ์ •ํ• ๊นŒ์š”?) WWDC21 - Demystify SwiftUI ๋ฅผ ๋ณด๋ฉด identity, life time, dependencies ์ด ์„ธ๊ฐ€์ง€ ์š”์ธ์ด ๋ฉ”์ธ์š”์†Œ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ €๋Š” ์ด ์ค‘์—์„œ identity ์œ„์ฃผ๋กœ ์ €์˜ re-rendering ์ถ”์ธก..

๐Ÿ/SwiftUI + Combine 2022. 11. 16. 23:56
[iOS] object_setClass ์˜ ์œ„ํ—˜์„ฑ

[1] ISA Swizzling Method Swizzling์ด ๋Ÿฐํƒ€์ž„์— ํŠน์ • ๋ฉ”์„œ๋“œ๋ฅผ ๋‹ค๋ฅธ ๋ฉ”์„œ๋“œ๋กœ ๋ฐ”๊ฟ”์„œ ์‹คํ–‰๋  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š” ๊ฒƒ์ด๋ผ๋ฉด, ISA Swizzling์€ ๋Ÿฐํƒ€์ž„์— ํŠน์ • ๊ฐ์ฒด๋ฅผ ๋‹ค๋ฅธ ๊ฐ์ฒด๋กœ ๋ฐ”๊ฟ”์„œ ์‹คํ–‰๋  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š” ๊ฒƒ์„ ๋งํ•ฉ๋‹ˆ๋‹ค. (isa ๋Š” ํฌ์ธํ„ฐ๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค) object_setClass ๋ฅผ ์ด์šฉํ•ด์„œ isa swizzling์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ๋“ค์–ด ๋‚˜์˜ ์ปค์Šคํ…€ ํƒญ๋ฐ”๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์€ ์ƒํ™ฉ์„ ๋ด…์‹œ๋‹ค. TabBarController์˜ tabBar ํ”„๋กœํผํ‹ฐ๋Š” get only ์ด๊ณ  ์ด๋ฅผ ์„ธํŒ…ํ•  ์ˆ˜ ์—†๋Š” ์ด๋‹ˆ์…œ๋ผ์ด์ €๋‚˜ ๋ฉ”์†Œ๋“œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ์ด ๋•Œ isa swizzling์„ ํ†ตํ•ด ๊ธฐ๋ณธ ํƒญ๋ฐ”๋ฅผ ์„œ๋ธŒํด๋ž˜์‹ฑํ•œ ์ปค์Šคํ…€ ํƒญ๋ฐ”๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. private class CustomTabBar: UI..

๐Ÿ/iOS 2022. 11. 4. 21:55
[Swift] some, any ํ‚ค์›Œ๋“œ

WWDC 2022 > Embrace Swift Generics ์— ๋‚˜์˜ค๋Š” ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. Feed (์‚ฌ๋ฃŒ, ๋จน์ด) ๋ฅผ associatedtype์œผ๋กœ ๊ฐ€์ง€๋Š” Animal ํ”„๋กœํ† ์ฝœ์„ ์˜ˆ์ œ๋กœ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. [1] AS IS Farm์— feed๋ผ๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ๋งŒ๋“ค๊ณ  ์‹ถ์„ ๋•Œ, ์•„๋ž˜ ๋‘๊ฐ€์ง€ ์ค‘ ํ•˜๋‚˜์˜ ๋ฐฉ๋ฒ•์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์คฌ์–ด์•ผํ–ˆ์Šต๋‹ˆ๋‹ค. ๋ฉ”์†Œ๋“œ๊ฐ€ ์ข€ ๋ณต์žกํ•ด๋ณด์ž…๋‹ˆ๋‹ค. [2] TO BE ํ•˜์ง€๋งŒ!! ์ด์ œ opaque type์ธ some์„ ์‚ฌ์šฉํ•˜์—ฌ, ์•„๋ž˜์™€ ๊ฐ™์ด ๊ฐ„๋‹จํ•œ ๋ฉ”์†Œ๋“œ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Swift 5.7๋ถ€ํ„ฐ๋Š” some์„ parameter type์—๋„ ์“ธ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค ๐Ÿ‘ (์ด์ „์—๋Š” ํ”„๋กœํผํ‹ฐ ํƒ€์ž…, ๋ฆฌํ„ด ํƒ€์ž…์—๋งŒ ์“ธ ์ˆ˜ ์žˆ์—ˆ์Œ) [3] some ๊ณผ any (1) ํ•˜์ง€๋งŒ,, some์€ ์ œ์•ฝ์ด ์žˆ๋Š”๋ฐ,, ์•„๋ž˜์™€ ๊ฐ™์ด..

๐Ÿ/Swift 2022. 7. 16. 20:29
๊ณต์ง€์‚ฌํ•ญ
Total
867,868
Today
438
Yesterday
1,696
ยซ   2023/02   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28
๊ธ€ ๋ณด๊ด€ํ•จ