๋ชฉ๋กiOS [Swift]/๊ธฐ์ดˆ๋ฅผ ํƒ„ํƒ„ํžˆ! (32)

Focus On Develop ๐ŸคŸ๐ŸคŸ

[Swift] Cloud Firestore(2) ์‹ค์Šตํ•ด๋ณด๊ธฐ

์ง€๋‚œ ํฌ์ŠคํŒ…์—์„œ๋Š” ๊ฐ„๋‹จํ•˜๊ฒŒ Cloud Firestore์— ๋ฐ์ดํ„ฐ๊ฐ€ ์–ด๋–ป๊ฒŒ ์ €์žฅ๋˜๋Š”์ง€ ์ „์ฒด์ ์ธ ๊ตฌ์กฐ๋ฅผ ์‚ดํŽด๋ณด์•˜๋Š”๋ฐ์š”~!! ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ๋ฅผ ์ž˜ ๋ชจ๋ฅด๋ฉด ๋จผ์ € ๊ตฌ์กฐ๋ถ€ํ„ฐ ํ™•์‹คํ•˜๊ฒŒ ์•Œ๊ณ  ์‹ค์Šต์„ ์‹œ์ž‘ํ•˜๋Š”๊ฒŒ ์ข‹์Šต๋‹ˆ๋‹ค ๐Ÿ‘๐Ÿ‘ ๐Ÿ‘‰ 2021/02/08 - [iOS [Swift]/๊ธฐ์ดˆ๋ฅผ ํƒ„ํƒ„ํžˆ!] - [Swift] Cloud Firestore(1) ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ ์ด๋ฒˆ์—๋Š” ์‹ค์ œ๋กœ XCode์—์„œ ์–ด๋–ป๊ฒŒ Firestore๋ฅผ ํ†ตํ•ด CURD๋ฅผ ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ์‹ค์Šตํ•ด๋ณผ๊ฑฐ์—์š”. ๋จผ์ € ์‹ค์Šต์„ ์œ„ํ•ด์„œ, Firestore๋ฅผ ๋น„์–ด์žˆ๊ฒŒ ์ค€๋น„ํ•˜๊ณ , Console์„ ๋ฐ”๋กœ๋ฐ”๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์›Œ์ค์‹œ๋‹ค! Database ์ฐธ์กฐ ๋ณธ๊ฒฉ CRUD ์‹ค์Šต์— ์•ž์„œ, ์šฐ๋ฆฌ๊ฐ€ Cloud์˜ Firestore์ด ์–ด๋””์žˆ๋Š”์ง€ ์œ„์น˜์ •๋ณด๋ฅผ ์•Œ์•„์•ผ CRUD๋ฅผ ์ง„ํ–‰ํ•˜๊ฒ ์ฃ ~? ์•„๋ž˜ ์ฝ”๋“œ๋กœ..

[Swift] Cloud Firestore(1) ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ

์˜ค๋Š˜์€ Google Firebase Cloud Firestore์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€ํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค! ์š”๊ธฐ ๋“ค์–ด๊ฐ€์„œ ๊ตฌ๊ธ€๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธํ•˜๊ณ  ๋‘˜๋Ÿฌ๋ณด์‹œ๊ธธ!! ใ…Žใ…Žใ…Ž console.firebase.google.com/ ๋กœ๊ทธ์ธ - Google ๊ณ„์ • ํ•˜๋‚˜์˜ ๊ณ„์ •์œผ๋กœ ๋ชจ๋“  Google ์„œ๋น„์Šค๋ฅผ Google ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธ accounts.google.com ์šฐ๋ฆฌ๊ฐ€ ์•ฑ์„ ๊ฐœ๋ฐœํ•  ๋•Œ ๋กœ์ปฌ ์ €์žฅ์†Œ์ธ UserDefault, CoreData๋งŒ ํ•„์š”ํ•œ ๊ฒฝ์šฐ๋Š” ์ œ์™ธํ•˜๊ณ , ๋ถ„๋ช…ํžˆ ์›๊ฒฉ Database๊ฐ€ ํ•„์š”ํ•˜๊ฒ ์ฃ ? ์˜ˆ๋ฅผ ๋“ค์–ด์„œ ์นด์นด์˜คํ†ก ์ฑ„ํŒ…์ด๋‚˜, ๊ณต์œ ๋ฌธ์„œํ•จ ๋“ฑ์„ ์‚ฌ์šฉ์ž A์™€ B๊ฐ€ ์„œ๋กœ ๋™๊ธฐํ™”๋˜๋Š” ์•ฑํ™”๋ฉด์„ ๋ด์•ผํ•œ๋‹ค๋ฉด, ๋กœ์ปฌ ์ €์žฅ์†Œ์— ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š” ๊ฒƒ๋งŒ์œผ๋กœ๋Š” ๋ถ„๋ช…ํžˆ ๋ถ€์กฑํ•˜๊ฒ ์ฃ ! A๊ฐ€ ์ฑ„ํŒ…์„ ๋ณด๋‚ด๋ฉด ์–ด๋”˜๊ฐ€ Database์— ๋‚ด์šฉ์ด ์ €์žฅ๋˜..

[Swift] ScrollView + PageControl

Storyboard์— ๋ณด๋ฉด pageControl์ด ์žˆ๋Š”๋ฐ, ๊ทธ๊ฒƒ๋งŒ ๋„ฃ์œผ๋ฉด ์ž๋™์œผ๋กœ ์ขŒ/์šฐ๋กœ swipeํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜๋‚˜?? ์‹ถ์—ˆ๋Š”๋ฐ.. ์•„๋‹ˆ๋”๋ผ๊ตฌ์š” ใ…Žใ…Žใ…Ž ์Œ.. ๊ทธ๋Ÿผ ์ด๊ฑฐ๋Š” ์–ด๋–ป๊ฒŒ ์“ฐ๋Š”๊ฑฐ์ง€? ํ•˜๋‹ค๊ฐ€ Tutorial Sample์„ ๋งŒ๋“ค์–ด๋ดค์–ด์š”~ ScrollView + PageControl์ด๋‚˜, CollectionView + PageControl์„ ๋งŽ์ด ์“ฐ๋Š” ๊ฒƒ ๊ฐ™๋”๋ผ๊ตฌ์š”. ๊ทธ ์ค‘์— ScrollView๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ฐ„๋‹จํ•˜๊ฒŒ ๊ตฌํ˜„ํ•ด๋ดค์Šต๋‹ˆ๋‹ค. Storyboard๋Š” ๊ฐ„๋‹จํžˆ ์ด๋ ‡๊ฒŒ ๊ตฌ์„ฑํ–ˆ์–ด์š”. ScrollView ์•ˆ์— View๋ฅผ ๋„ฃ๊ณ  Constraint๋ฅผ ๋งž์ถœ๋•Œ๋Š” ๋ญ”๊ฐ€ ์—๋Ÿฌ๊ฐ€ ๋งŽ์ด ๋ฐœ์ƒํ–ˆ์—ˆ์ฃ ?ใ…‹ใ…‹ ์ด๋ฒˆ์—๋Š” ๋”ฐ๋กœ ๋ฐ์ดํ„ฐ ์—†์ด ๋ทฐ๋งŒ ๋”ฑ ์žก์•„์ฃผ๊ธฐ!! ์ž ๊น ํ‹ˆ์ƒˆ๋กœ ์—ฌ๊ธฐ์„œ ScrollView์— View๋ฅผ ๋„ฃ์„๋•Œ Constra..

[Swift] CGRect, CGSize, CGPoint

๊ณต๋ถ€๋ฅผ ํ•˜๋ฉด ํ• ์ˆ˜๋ก Interface Builder ๋กœ๋งŒ UI์ž‘์—…์„ ํ•˜๋Š”๊ฒŒ ํ•œ๊ณ„๊ฐ€ ์žˆ๋”๋ผ๊ตฌ์š”! ๐Ÿ‘‰ Storyboard vs Programmatic UI ๋ฐ”๋กœ๋ณด๊ธฐ ๊ทธ๋ž˜์„œ ์ €๋Š” Programmatically AutoLayout์— ์ž…๋ฌธํ–ˆ์Šต๋‹ˆ๋‹ค!! ์ด๋Ÿฐ ์ €๋Ÿฐ ์†Œ์Šค๋ฅผ ๋ณด๋ฉด CG ์–ด์ฉŒ๊ตฌ ์ €์ฉŒ๊ตฌ..๊ฐ€ ๋‚˜์˜ค๋Š”๋ฐ, ๋‚ด๊ฐ€ ์•„๋Š” CG๋Š” ์˜ํ™”๋ณด๋ฉด์„œ "์—์ด~์ €๊ฑฐ CG๋„ค" ๋ผ๊ณ  ํ•˜๋Š” ๊ฒƒ ๋ฟ์ธ๋ฐ..๐Ÿ˜‚๐Ÿ˜‚ ๊ทธ๋ž˜์„œ ํ•˜๋‚˜ํ•˜๋‚˜ ๊ธฐ์ดˆ์ ์ธ ๊ฒƒ๋ถ€ํ„ฐ ์ •๋ฆฌํ•ด๊ฐ€๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค!! ๋จผ์ €, CG CG ํ•˜๋Š”๋ฐ CG๊ฐ€ ๋ญ˜๊นŒ์š”~? ๊ทธ๋ ‡๋Œ€์š”. ๊ฐ„๋‹จํžˆ ๋งํ•˜๋ฉด Swift์—์„œ 2์ฐจ์›์ƒ์˜ ํ™”๋ฉด์„ ๊ทธ๋ฆด๋•Œ ์‚ฌ์šฉํ•˜๋Š” Framework๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค! ๋งŽ์ด ๋“ค์–ด๋ณธ CGFloat, CGPoint, CGSize, CGRect, CGColor, CGFont ๋“ฑ๋“ฑ ๋‹ค์–‘ํ•œ ์š”์†Œ๊ฐ€ ์š” Fra..

[Swift] Storyboard vs Programmatic UI

์ €๋Š” ์™•์ดˆ๋ณด์ดˆ๋ณด๋ผ์„œ, ๋ฐฐ์šด๋Œ€๋กœ ์ถฉ์‹คํ•˜๊ฒŒ Storyboard๋ฅผ ํ†ตํ•œ UI์ž‘์—…๋งŒ ํ•ด์™”๋Š”๋ฐ์š”~! ๊ณต๋ถ€๋ฅผ ํ•˜๋ฉด ํ• ์ˆ˜๋ก ๋ณต์žกํ•˜๊ฑฐ๋‚˜ ๋‹ค์–‘ํ•œ User Interaction(swipe ๋“ฑ)์ด ํ•„์š”ํ•œ ํ™”๋ฉด๋“ค์„ ๋งŒ๋‚˜๊ฒŒ ๋˜๊ณ , ๊ทธ๊ฒƒ๋“ค์„ ๋” ์ž˜ ๊ตฌํ˜„ํ•˜๋ ค๋ฉด Code Base๋กœ Programaticํ•˜๊ฒŒ UI๋ฅผ ๊ทธ๋ฆด ์ˆ˜๋„ ์žˆ์–ด์•ผ ๊ฒ ๋”๋ผ๊ตฌ์š”! ๊ทธ๋ž˜์„œ ์ด๋ฒˆ์—๋Š” CodeBase๋กœ๋„ UI๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•˜๋Š” ์ด์œ ๋ฅผ ํฌ์ŠคํŒ… ํ•ด๋ณผ๊ฑฐ์—์š”! Storyboard๋กœ ๊ฐœ๋ฐœํ• ๋•Œ ์žฅ/๋‹จ์  ์žฅ์  ๊ฒฐ๊ณผ๋ฌผ์— ๊ด€ํ•ด ์˜ˆ์ธกํ•˜๊ธฐ ์‰ฌ์›€ (๋‹น์—ฐํžˆ ๋ˆˆ์œผ๋กœ ๋ณด๋ฉด์„œ ํ™”๋ฉด์„ ๊ทธ๋ฆฌ๋‹ˆ๊นŒ..?) ์†์„ฑ ํ™•์ธ ๊ฐ€๋Šฅ (inspector ํ™”๋ฉด์„ ๋ณด๋ฉด์„œ ํ•˜๋ฉด ํด๋ฆญ ๋”ธ๊น ๋”ธ๊น์œผ๋กœ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ™•์ธ ๊ฐ€๋Šฅํ•˜์ฃ !) ์†Œ์Šค์ฝ”๋“œ๋ฅผ ํ•˜๋‚˜ํ•˜๋‚˜ ๊ธฐ์–ตํ•˜์ง€ ์•Š์•„๋„ ๋ฌด๊ด€ ๋‹จ์  ๋ฌด๊ฑฐ์›€ ๐Ÿ˜ฉ (์•„๋งˆ ๋ณต์žกํ•œ ํ™”๋ฉด ์ž‘์—…..

[Swift] strong, weak, unowned

๋จผ์ € ARC์˜ ๊ฐœ๋…์— ๋Œ€ํ•ด์„œ ์งš๊ณ  ๋„˜์–ด์™€์•ผ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜์— ๋Œ€ํ•œ ์ด์•ผ๊ธฐ๊ฐ€ ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿ‘ ๐Ÿ‘‰ 2021/01/29 - [iOS [Swift]] - [Swift] ARC (Automatic Reference Counting) ์ž ๊น ์š”์•ฝํ•˜๋ฉด ARC๋Š” Swift์—์„œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ž๋™์œผ๋กœ ๊ด€๋ฆฌํ•ด์ค€๋‹ค๋Š” ๊ฐœ๋…์ธ๋ฐ, ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ๋ฅผ ์ž๋™์œผ๋กœ ํ•ด์ฃผ์ง€๋งŒ ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ํฌ์ธํŠธ๊ฐ€ ์žˆ์—ˆ์ฃ . ๊ทธ ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ํฌ์ธํŠธ๋Š” ์–ธ์ œ์ด๋ฉฐ, ์–ด๋–ป๊ฒŒ ๋ฐฉ์ง€๋ฅผ ํ•ด์•ผ ํ• ์ง€์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋ ค ํ•ฉ๋‹ˆ๋‹ค. ** ์—ฌ๊ธฐ์„œ๋ถ€ํ„ฐ๋Š” Swift ๊ณต์‹ Document๋ฅผ ์ฐธ๊ณ ํ•ด์„œ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค ** [Swift Docs] docs.swift.org/swift-book/LanguageGuide/AutomaticReferenceCounting.htm..

[Swift] ARC (Automatic Reference Counting)

Swift์—์„œ๋Š” ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ๋ฅผ ์–ด๋–ป๊ฒŒ ํ• ๊นŒ์š”~? Swift์—์„œ ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜๋ฅผ ๋ฐฉ์ง€ํ•˜๊ณ  ์„ฑ๋Šฅ์ €ํ•˜๋ฅผ ๋ง‰๊ธฐ์œ„ํ•ด ARC ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š”๋ฐ์š”! ์ด ARC์— ๋Œ€ํ•ด์„œ ํ•œ๋ฒˆ ์•Œ์•„๋ณด๋ ค๊ณ  ํ•ด์š”! RC๋ž€ Reference Counting์˜ ์•ฝ์ž๋กœ ์• ํ”Œ์—์„œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. ๋ผ๋Š” ๊ธฐ๋ณธ์ ์ธ Rule์ด๋ผ๋Š” ์ „์ œ๋ฅผ ๋‘ก๋‹ˆ๋‹ค. MRC๋ž€ Manual Reference Counting์˜ ์•ฝ์ž๋กœ Object-C์—์„œ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ง์ ‘! ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ• ๋‹น/ํ•ด์ œ ํ•ด์ค˜์•ผ ํ• ๋•Œ ์“ฐ๋Š” ๋ฐฉ๋ฒ•์ด๋ผ๊ณ  ํ•˜๋Š”๋ฐ, ์ด ๋ถ€๋ถ„์€ ์ฟจํ•˜๊ฒŒ ์š”์ •๋„๋กœ ํŒจ์Šคํ•ฉ๋‹ˆ๋‹ค.ใ…Ž ์ด๋ฏธ Swift๊ฐ€ ๋ณดํŽธํ™” ๋˜์—ˆ๊ณ , ์ € ๋˜ํ•œ Object-C๋Š” 1๋„ ๋ชจ๋ฅด๊ณ  ํ˜„์žฌ ์‚ฌ์šฉ๋„ ์•ˆํ•˜๊ธฐ ๋•Œ๋ฌธ..ใ…‹๐Ÿ‘๐Ÿ‘ ์ž ์ด์ œ ๋ณธ๋ก ์œผ๋กœ ๋“ค์–ด๊ฐ€์„œ, ARC๋ž€ Automatic Reference Counting์˜..

[Swift] ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ฝ”๋”ฉ์‹œ ์œ ์šฉํ•œ Tip๋“ค!

์ด ํŽ˜์ด์ง€๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ๋ฅผ ํ’€๋•Œ ์ž์ฃผ(?) ์“ฐ์ด๋Š” ์Šคํ‚ฌ(?) ๊ฐ™์€ ๊ฒƒ๋“ค์„ ๊ฐ„๋žตํ•˜๊ฒŒ ์ •๋ฆฌํ•ด๋‘˜ ์˜ˆ์ •์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด์„œ ์Œ..? root๊ฐ’ ์–ด๋–ป๊ฒŒ ๊ตฌํ•˜์ง€.. ์ง„๋ฒ•๋ณ€ํ™˜ ์–ด๋–ป๊ฒŒ ํ•˜์ง€.. ๋“ฑ๋“ฑ! (๋งค๋ฒˆ ๊ตฌ๊ธ€๋งํ•˜๊ธฐ ๋„˜ ๊ท€์ฐฎ..๐Ÿ˜”) ์ •~๋ง ๊ฐ„๋‹จํ•˜๊ฒŒ ์‚ฌ์šฉ๋ฒ•๋งŒ ์ •๋ฆฌํ•  ์˜ˆ์ •์ด๋ž๋‹ˆ๋‹ค ๐Ÿ˜Ž ๋ฌธ์ œ ํ’€๋ฉด์„œ ๋˜ ์ž์ฃผ ๋ณด์ด๋Š” ๊ฒƒ์€ ์ด ํŽ˜์ด์ง€์— ์ถ”๊ฐ€ํ•ด๋‚˜๊ฐˆ ์˜ˆ์ •์ž…๋‹ˆ๋‹ค ๐Ÿ‘๐Ÿ‘ - ๋ฐฐ์—ด ์ดˆ๊ธฐ๊ฐ’ ๋„ฃ์–ด์„œ ๋งŒ๋“ค๊ธฐ var array = Array(1...5) // [1,2,3,4,5] - ํฌ๊ธฐ๊ฐ€ ์ •ํ•ด์ง„ ๋ฐฐ์—ด ๋งŒ๋“ค๊ธฐ var arr = Array(repeating: 0, count: 3) // [0,0,0] - 2์ฐจ์› ๋ฐฐ์—ด ๋งŒ๋“ค๊ธฐ let array: [[Int]] = Array(repeating:Array(repeating:1, count: 4), c..