๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
728x90

๐ŸŽ iOS/SwiftUI8

[iOS] SwiftUI - SignInWithAppleButton / ์• ํ”Œ ๋กœ๊ทธ์ธ ์ปค์Šคํ…€ ๋ฒ„ํŠผ structure SignInWithAppleButton https://developer.apple.com/documentation/authenticationservices/signinwithapplebutton SwiftUI / iOS 14.0 + ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ Labels continue signIn signUp Styles black white whiteOutline Sample code SignInWithAppleButton(.continue) { request in request.requestedScopes = [.fullName, .email] } onCompletion: { result in switch result { case .success(let authResults): print.. 2023. 10. 22.
[iOS] SwiftUI - GeometryReader / View ํฌ๊ธฐ์™€ ์ขŒํ‘œ ๊ณ„์‚ฐํ•˜๊ธฐ https://developer.apple.com/documentation/swiftui/geometryreader ์Šค์œ  ๊ณต๋ถ€ํ•˜๊ธฐ ๐Ÿง GeometryReader GeometryReader ๋Š” ์ปจํ…์ธ ์˜ ํฌ๊ธฐ์™€ ์œ„์น˜๋ฅผ ํ•จ์ˆ˜๋กœ ๋‚˜ํƒ€๋‚ด๋Š” ์ปจํ…Œ์ด๋„ˆ ๋ทฐ๋กœ, ๋ถ€๋ชจ ๋ทฐ์˜ ์‚ฌ์ด์ฆˆ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ๋Š” HStack, VStack, ZStack ์„ ์‚ฌ์šฉํ•ด์„œ ๋ ˆ์ด์•„์›ƒ์„ ๋ฐฐ์น˜ํ•˜์ง€๋งŒ, UIKit ์„ ๊ฐ™์ด ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ํ˜น์€ ์„ธ๋ถ€์ ์ธ ์กฐ์ •์ด ํ•„์š”ํ•  ๊ฒฝ์šฐ ์‚ฌ์šฉํ•  ๊ฒƒ์œผ๋กœ ๋ณด์ด๋„ค์š” ๐Ÿ‘€ View ์˜ ํฌ๊ธฐ๋‚˜ ์ขŒํ‘œ๋ฅผ ๊ณ„์‚ฐํ•˜๊ณ  ์‹ถ์„๋•Œ ํ™œ์šฉ๋„ ๊ฐ€๋Šฅํ•ด๋ณด์ž…๋‹ˆ๋‹ค! ๐Ÿค” GeometryReader ์‚ฌ์šฉํ•ด์„œ ๋ ˆ์ด์•„์›ƒ ๋ฐฐ์น˜ํ•ด๋ณด๊ธฐ GeometryReader ์ƒ์„ฑ์ž์˜ ํด๋กœ์ € ์ธ์ž๋Š” GeometryProxy ๋กœ ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค. GeometryProxy : ์ปจํ…Œ.. 2023. 10. 21.
[iOS/SwiftUI] @Environment ์•Œ์•„๋ณด๊ธฐ / ๋ชจ๋‹ฌ ๋ทฐ ๋‹ซ๊ธฐ dismiss ํ™œ์šฉ Environment A property wrapper that reads a value from a view’s environment. @Environment ๋Š” SwiftUI ๋ทฐ ๋‚ด์—์„œ ์•ฑ์˜ ์ „์—ญ์ ์ธ ์ƒํƒœ์™€ ์†์„ฑ์„ ์ €์žฅํ•˜๊ณ  ๊ณต์œ ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” ํ”„๋กœํผํ‹ฐ ๋ž˜ํผ์ด๋‹ค. ํ•ด๋‹น ๋ž˜ํผ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด SwiftUI ๊ฐ€ ํ•ด๋‹น ๊ฐ’์— ์•ก์„ธ์Šคํ•˜๊ณ  ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์ž๋™์œผ๋กœ ๊ฐ์ง€ํ•ด์„œ ๋ทฐ๋ฅผ ์—…๋ฐ์ดํŠธ ํ•  ์ˆ˜ ์žˆ๋‹ค. Environment ํ‚ค๋ฅผ ์‚ฌ์šฉ์ž ์ •์˜ํ•ด์„œ ์ถ”๊ฐ€์ ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์•ฑ ์ „์—ญ์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๋ฐ์ดํ„ฐ, ์„ค์ •, ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด ์ €์žฅ์— ์œ ์šฉํ•˜๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” Environment ํ‚ค https://developer.apple.com/documentation/swiftui/environmentvalues \.dism.. 2023. 6. 15.
[iOS/SwiftUI] @ViewBuilder, @resultBuilder ๊ฐ€ ๋ฌด์—‡์ผ๊นŒ? ViewBuilder A custom parameter attribute that constructs views from closures. @resultBuilder struct ViewBuilder SwiftUI ์—์„œ ViewBuilder ๋Š” ํด๋กœ์ ธ๋ฅผ ํ†ตํ•ด ๋ทฐ ๊ณ„์ธต์„ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋Š” ์†์„ฑ์ด๋‹ค. ViewBuilder ๋ฅผ ์ด์šฉํ•˜๋ฉด ํ•จ์ˆ˜๋‚˜ ํด๋กœ์ €๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ทฐ๋ฅผ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ๋‹ค. ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ทฐ๋ฅผ ์ „๋‹ฌํ•ด์•ผํ•˜๋Š” ์ƒํ™ฉ์—์„œ ์ฝ”๋“œ๋ฅผ ๊น”๋”ํ•˜๊ฒŒ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. ๐Ÿ˜ฏ resultBuilder ? ViewBuilder ๋Š” @resultBuilder ํ”„๋กœํผ๋ฆฌ ๋ž˜ํผ๊ฐ€ ๋ถ™์–ด ์žˆ๋Š”๋ฐ ํ•ด๋‹น ์†์„ฑ์€ Swift5.4 ์— ๋„์ž…๋˜์—ˆ๊ณ  ๊ธฐ์กด ๋ช…์นญ์€ @_functionBuilder ์ด๋‹ค. SE-0289์˜ ResultBuilder resultBu.. 2023. 6. 7.
[iOS] SwiftUI LazyVStack LazyHStack :: lazy load views ์•ˆ๋…•ํ•˜์„ธ์š”! ์˜ค๋Š˜์€ SwiftUI ์˜ Lazy ํ‚ค์›Œ๋“œ๋ฅผ ์ •๋ฆฌํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์ง€๋‚œ๋ฒˆ์— VStack, HStack, ZStack ์— ๋Œ€ํ•ด์„œ ์ •๋ฆฌ๋ฅผ ํ–ˆ์—ˆ๋Š”๋ฐ, ZStack ์„ ์ œ์™ธํ•˜๊ณ ๋Š” ์•ž์— Lazy ๋ผ๋Š” ํ‚ค์›Œ๋“œ๊ฐ€ ๋ถ™์€ LazyVStack, LazyHStack ์ด ์žˆ์Šต๋‹ˆ๋‹ค ๐Ÿ‘€ Lazy ๋ผ๋Š” ํ‚ค์›Œ๋“œ๊ฐ€ ๋ถ™๋Š” ๊ฑด ์–ด๋–ค ์ฐจ์ด๊ฐ€ ์žˆ๋Š”์ง€ ๊ถ๊ธˆํ•ด์„œ ์ฐพ์•„๋ดค์–ด์š”. ๐Ÿ‘€ LazyVStack LazyHStack :: lazy load views LazyVStack ์€ VStack ๊ณผ ๋™์ผํ•˜๊ฒŒ vertical (์„ธ๋กœ) ๋ฐฉํ–ฅ์œผ๋กœ ํ•ญ๋ชฉ๋“ค์„ ๋ณด์—ฌ์ฃผ๋Š” ๋ทฐ์ด์ง€๋งŒ, ๊ฐ ํ•ญ๋ชฉ์ด ํ•„์š”ํ• ๋•Œ๋งŒ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. LazyHStack ์€ Horizontal (๊ฐ€๋กœ) ๋ฐฉํ–ฅ์œผ๋กœ, LazyVStack ๊ณผ ๋ฐฉํ–ฅ๋งŒ ๋‹ค๋ฅด๊ณ  ๋™์ผํ•ฉ๋‹ˆ๋‹ค! Stack ์ด lazy ํ•˜๋‹ค๋Š” ๊ฒƒ.. 2022. 6. 7.
[iOS] SwiftUI property wrapper @State @Binding @State SwiftUI ๋Š” state ๋กœ ์„ ์–ธํ•œ ํ”„๋กœํผํ‹ฐ์˜ ์ €์žฅ์†Œ๋ฅผ ๊ด€๋ฆฌํ•œ๋‹ค. ํ•ด๋‹น ํ”„๋กœํผํ‹ฐ์˜ ๊ฐ’์ด ๋ณ€๊ฒฝ๋  ๋•Œ, SwiftUI ๋Š” ๊ฐ’์— ์˜์กดํ•˜๊ณ  ์žˆ๋Š” ๋ทฐ ๊ณ„์ธต๊ตฌ์กฐ์˜ ๋ถ€๋ถ„์„ ์—…๋ฐ์ดํŠธํ•œ๋‹ค. State ํ”„๋กœํผํ‹ฐ๋Š” ํ•˜๋‚˜์˜ ๋ทฐ ์•ˆ์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๊ฐ’์œผ๋กœ, ์ผ๋ฐ˜์ ์œผ๋กœ private ํ‚ค์›Œ๋“œ๋ฅผ ๋ถ™์—ฌ์„œ ์‚ฌ์šฉํ•œ๋‹ค. State instance ๋Š” ๊ฐ’(value)์„ ์ฝ๊ณ  ์“ธ ์ˆ˜ ์žˆ๋Š” ํ˜•ํƒœ์ด๊ธฐ ๋•Œ๋ฌธ์—, value ์™€ ๋™์ผํ•˜์ง€๋Š” ์•Š๋‹ค. state ๊ฐ€ ๊ฐ–๊ณ ์žˆ๋Š” value ์— ์•ก์„ธ์Šคํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”, property name ์„ ํ†ตํ•ด ์ ‘๊ทผํ•˜๋ฉด ๋œ๋‹ค. ํ•ด๋‹น ๊ฐ’์€ wrappedValue ์†์„ฑ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. wrappedValue ๋Š” state ๋ณ€์ˆ˜๊ฐ€ ์ €์žฅํ•˜๊ณ  ์žˆ๋Š” ๊ฐ’์„ ์ ‘๊ทผํ•˜๋Š” ํ”„๋กœํผํ‹ฐ์ด์ง€๋งŒ, wrappedValue ๋ฅผ ์ง์ ‘ ์ ‘๊ทผํ•ด์„œ๋Š” ์•ˆ๋œ.. 2022. 6. 2.
[iOS/SwiftUI] Text, Image ๊ธฐ๋ณธ ์ •๋ฆฌ + ์‹œ์Šคํ…œ ์ด๋ฏธ์ง€ โœ๏ธ Text Text ๋Š” ํ•œ์ค„ ์ด์ƒ์˜ ์ฝ๊ธฐ ์ „์šฉ ๊ธ€์ž๋ฅผ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•œ View ์ž…๋‹ˆ๋‹ค. Text initializer Text ์ƒ์„ฑ์ž๋Š” ์—ฌ๋Ÿฌ๊ฐ€์ง€๊ฐ€ ์žˆ๋Š”๋ฐ, ์ด๋ฏธ์ง€๋กœ๋„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋Š”๊ฒŒ UIKit ๊ณผ๋Š” ๋‹ค๋ฅธ๊ฑฐ ๊ฐ™์•„์š”. NSAttributedString ์„ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐ€๋Šฅํ•˜๊ธด ํ–ˆ์ง€๋งŒ, ๊ธฐ๋ณธ์ ์œผ๋กœ ์ด๋ฏธ์ง€๋ฅผ ํ…์ŠคํŠธ์™€ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ๊ฒŒ ์ œ๊ณตํ•ด์ฃผ๋„ค์š”. init(String) → ๋‹จ์ˆœ ๋ฌธ์ž์—ด, Localized ๊ด€๋ จ ์ƒ์„ฑ์ž๋„ ๋”ฐ๋กœ ์žˆ์–ด์š”. init(AttributedString) → NSAttributedString ์ด๋ž‘ ๋‹ค๋ฆ…๋‹ˆ๋‹ค. (+iOS15) init(Image) → ๋‹ค๋ฅธ Text ๋“ค์ด๋ž‘ ์—ฐ๊ฒฐํ•˜๊ธฐ์œ„ํ•œ Image init(_ date: Date, style: Text.DataStyle) Text.DataStyle .. 2022. 5. 5.
[iOS/SwiftUI] View, Stack ๊ธฐ๋ณธ ์ •๋ฆฌ SwiftUI ๋Š” UIKit ๊ณผ ๋น„์Šทํ•˜๊ฒŒ iOS ์•ฑ์˜ UI ๋ฅผ ๊ทธ๋ฆฌ๊ธฐ ์œ„ํ•œ ํ”„๋ ˆ์ž„์›Œํฌ์ž…๋‹ˆ๋‹ค. iOS13 ๋ถ€ํ„ฐ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜์ง€๋งŒ iOS14 ์ด์ƒ๋ถ€ํ„ฐ ๊ฐ€๋Šฅํ•œ ๊ธฐ๋Šฅ๋“ค์ด ๋งŽ์•„, ๋ฏธ๋‹ˆ๋ฉˆ iOS14 ์—์„œ ์ฃผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฑธ๋กœ ์•Œ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค! ๋‹ค์Œ ์‚ฌ์ด๋“œํ”„๋กœ์ ํŠธ๋‚˜ ํด๋ก ์ฝ”๋”ฉ์€ SwiftUI ๋กœ ๊ผญ ํ•ด๋ด์•ผ๊ฒ ์–ด์š”!! ๊ทธ๋Ÿฌ๊ธฐ ์œ„ํ•œ ์Šคํ„ฐ๋”” ์‹œ์ž‘~! ๐Ÿ’ช SwiftUI ์— ๋Œ€ํ•œ ํŠน์ง• - ์„ ์–ธ์  ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•ด ์‚ฌ์šฉ์ž ์ธํ„ฐํŽ˜์ด์Šค์˜ ๊ธฐ๋Šฅ์„ ๋ช…์‹œํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. - ๋“œ๋ž˜๊ทธ ์•ค ๋“œ๋กญ์œผ๋กœ UI ๋ฅผ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๊ณ , ๋ฏธ๋ฆฌ๋ณด๊ธฐ๊ฐ€ ๊ฐ€๋Šฅํ•œ ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. (๊ณผ์—ฐ ์ž์ฃผ์“ธ์ง€ ์˜๋ฌธ์ด์ง€๋งŒ์š”) - ์‚ฌ์šฉ์ž ์ธํ„ฐํŽ˜์ด์Šค์˜ ์†์„ฑ์€ ๋ฉ”์†Œ๋“œ ์ฒด์ด๋‹(Method Chaining) ๋ฌธ๋ฒ•์„ ์ด์šฉํ•ด ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. View ํ”„๋กœํ† ์ฝœ์˜ Instance method ๋ฅผ ๋ณด๋ฉด.. 2022. 4. 29.
728x90