Deep_Dev
[Swift]11 : ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ์„œ ํด๋กœ์ €

๐Ÿ“– Day 11 : ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ์„œ ํด๋กœ์ € ๐Ÿ’ก Closure ๐Ÿ“Œ Closure ํ‘œํ˜„์‹ ์ต๋ช…์ด๊ธฐ ๋•Œ๋ฌธ์— func๋ผ๋Š” ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.

[Swift]10 : Closure

๐Ÿ“– Day 10 : Closure ( ํด๋กœ์ € ) ๐Ÿ’ก Closure Named Closure Unnamed Closure ์ด๋ฆ„์ด ์žˆ๋Š” ๋ณดํ†ต์˜ ํ•จ์ˆ˜๋Š” Named Closure ์ด๊ณ , ์ด๋ฆ„์ด ์—†๋Š” ํ•จ์ˆ˜๋“ค์„ unNamedClosure (์ต๋ช…ํ•จ์ˆ˜) ๋ผ๊ณ  ํ•œ๋‹ค. ๋ณดํ†ต ํด๋กœ์ €๋Š” unNamed๋œ ํ•จ์ˆ˜๋ฅผ ๋งํ•œ๋‹ค. ๐Ÿ“Œ Closure ํ‘œํ˜„์‹ ์ต๋ช…์ด๊ธฐ ๋•Œ๋ฌธ์— func๋ผ๋Š” ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. { (Parameters) -> ReturnType in ์‹คํ–‰๊ตฌ๋ฌธ } ๐Ÿ“Œ String์„ ๋ฐ˜ํ™˜ํ•˜๋Š” Closure let myName : String ={ // myName์œผ๋กœ ๋“ค์–ด๊ฐ„๋‹ค return "์Šค์œ„ํ”„ํŠธ" }() print(myName) >>> ์Šค์œ„ํ”„ํŠธ ๐Ÿ“Œ Closure ์ •์˜ ์ดํ•ดํ•˜๊ธฐ let myRealName : (String)..

article thumbnail
[Swift]09 : Generic

๐Ÿ“– Day 09 : Generic ( ์ œ๋„ค๋ฆญ ) ๐Ÿ’ก Generic : ์–ด๋– ํ•œ ์ž๋ฃŒํ˜•์ด๋“  ๋ฐ›๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•˜๋Š”, ๋ฒ”์šฉ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ ์‚ฌ์šฉ ๐Ÿ“Œ ์ œ๋„ค๋ฆญ ํ•จ์ˆ˜ ์ œ๋„ค๋ฆญ์€ ์„ ํ†ตํ•ด ๋‚˜ํƒ€๋‚ด๊ณ , ์ด ์•ˆ์— ํƒ€์ž…์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•  ์ด๋ฆ„์„ ๋„ฃ์–ด์ฃผ๋ฉด ๋œ๋‹ค. ๋ณดํ†ต์€ T๋ฅผ ๋งŽ์ด ๋„ฃ๋Š”๋‹ค. ๐Ÿ’ฌ ๋‹ค์–‘ํ•œ Type ์˜ˆ์‹œ ์ถœ๋ ฅ var mySomeArray = MyArray([1,2,3]) print("mySomeArray : \(mySomeArray)") var myStringArray = MyArray(["๊ฐ€", "๋‚˜"]) print("myStringArray : \(myStringArray)") >>> mySomeArray : MyArray(elements: [1, 2, 3]) >>> myStringArray : MyArray(eleme..

article thumbnail
[Swift]08 : ํ•จ์ˆ˜ ๋งค๊ฐœ๋ณ€์ˆ˜ ์ด๋ฆ„ ์„ค์ •

๐Ÿ“– Day 08 : ํ•จ์ˆ˜ ๋งค๊ฐœ๋ณ€์ˆ˜ ์ด๋ฆ„ ๐Ÿ“Œ ํ•จ์ˆ˜ ๋งค๊ฐœ๋ณ€์ˆ˜ ์ด๋ฆ„ ์„ค์ • func myFunction(name : String) -> String{ return "์•ˆ๋…•ํ•˜์„ธ์š”?! \(name) ์ž…๋‹ˆ๋‹ค!" } myFunction(name:"Deep_Lee") // >>> ์•ˆ๋…•ํ•˜์„ธ์š”?! Deep_Lee์ž…๋‹ˆ๋‹ค! ๐Ÿ’ฌ name : ๋งค๊ฐœ๋ณ€์ˆ˜ ์ด๋ฆ„, ->๋Š” String์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค๋Š” ๋œป ๐Ÿ“Œ ์ „๋‹ฌ ์ธ์ž ๋ ˆ์ด๋ธ” func myFunctionSecond(myName name:String)-> String{ return "์•ˆ๋…•ํ•˜์„ธ์š”?! \(name) ์ž…๋‹ˆ๋‹ค!" } myFunctionSecond(with : "์Šค์œ„ํ”„ํŠธ") // >>> ์•ˆ๋…•ํ•˜์„ธ์š”?! ์Šค์œ„ํ”„ํŠธ์ž…๋‹ˆ๋‹ค! ๐Ÿ’ฌ ๊ฐ™์€ ๋ฉ”์†Œ๋“œ์ด์ง€๋งŒ ์ด๋ฆ„์„ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๋‹ค. ๐Ÿ’ฌ with๋ผ๋Š” ์ „๋‹ฌ์ธ์ž ๋ ˆ..

article thumbnail
[Swift]07 : Property Observer

๐Ÿ“– Day 07 : Property Observer ( ํ”„๋กœํผํ‹ฐ ์˜ต์ €๋ฒ„ ) ๐Ÿ“Œ Property Observer : ํŠน์„ฑ ๊ด€์ฐฐ์ž ์ฆ‰, ํ”„๋กœํผํ‹ฐ ๊ฐ’์˜ ๋ณ€ํ™”๋ฅผ ๊ด€์ฐฐํ•œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ๐Ÿ’ก 2๊ฐ€์ง€ ์˜ต์…˜ willSet : ๊ฐ’์ด ์ €์žฅ๋˜๊ธฐ ์ง์ „์— ํ˜ธ์ถœ didSet : ์ƒˆ ๊ฐ’์ด ์ €์žฅ๋œ ์งํ›„์— ํ˜ธ์ถœ

article thumbnail
[Swift]06 : Class vs Struct

๐Ÿ“– Day 06 : Class vs Struct ์ฐจ์ด struct๋Š” ๋ณต์‚ฌ, class๋Š” ๊ณต์œ  ์ฆ‰, struct๋Š” ์ฐธ์กฐํ•˜๋Š” ๊ฐ’์ด ๋ฐ”๋€Œ์–ด๋„ ๊ธฐ์กด์˜ ๊ฐ’์— ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š๊ณ  class๋Š” ์˜ํ–ฅ์„ ๋ฏธ์นœ๋‹ค. ์ถœ๋ ฅ ๊ฒฐ๊ณผ ๊ธฐ์กด ๊ฐ์ฒด A์™€ ์ด ๊ฐ์ฒด๋ฅผ ๋ณต์‚ฌํ•œ ํด๋ก A๊ฐ€ ์žˆ์„๋•Œ, struct์˜ ๊ฒฝ์šฐ -> ํด๋ก A์˜ ๊ฐ’์„ ๋ณ€๊ฒฝํ•ด๋„, ๊ธฐ์กด๊ฐ์ฒด A์— ์˜ํ–ฅ์ด ๊ฐ€์ง€ ์•Š๋Š”๋‹ค. class์˜ ๊ฒฝ์šฐ -> ํด๋ก A์˜ ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๋ฉด, ๊ธฐ์กด๊ฐ์ฒด A์—๋„ ์˜ํ–ฅ์ด ๊ฐ„๋‹ค. ๐Ÿ’กStruct struct๋Š” ๋ณต์ œํ•˜๋ฉด ๋‹ค๋ฅธ ๊ฐœ์ฒด์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๋Š”๋‹ค. ๐Ÿ’กClass class๋Š” ์„œ๋กœ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๋‹ค. ๋ณธ ๋”ฐ์„œ ๋˜‘๊ฐ™์€๊ฑธ ๋งŒ๋“ค๊ณ  ํ•œ ์ชฝ์„ ํ›ผ์†ํ•˜๋ฉด, ๋‹ค๋ฅธ ํ•œ ์ชฝ๋„ํ›ผ์†๋˜๋ฉฐ ๋‚ด๊ฐ€ ์ˆ˜์ •ํ•œ ๋‚ด์šฉ์„ ๋‹ค๋ฅธ ์‚ฌ๋žŒ๋“ค์ด ๋‹ค ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ๊ฐ™์€ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์„ ์œ ์ง€ํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์ถœ์ฒ˜:๊ฐœ..

article thumbnail
[Swift]05 : Unwrap ์˜ต์…”๋„๋ณ€์ˆ˜

๐Ÿ“–Day 05 : Optional Unwrap ์‚ฌ์šฉ๋ฐฉ๋ฒ• ๐Ÿ’กOptional : ๊ฐ’์ด ์žˆ๋Š”์ง€ ์—†๋Š”์ง€ ๋ชจ๋ฅธ๋‹ค. ๐Ÿ’กUnwrapping : ๋žฉ. ์ฆ‰, ๊ฐ์‹ธ์ ธ์žˆ๋Š” ๊ฒƒ์„ ๋ฒ—๊ธฐ๋Š” ๊ฒƒ 1. someVariable์— ๊ฐ’์„ ์•„์ง ์„ค์ •ํ•˜์ง€ ์•Š์•˜๋‹ค. ( ๊ฐ’์ด ๋น„์—ˆ๋‹ค ) 2. someVaraible==nil ( ๊ฐ’์ด ๋น„์–ด์žˆ๋‹ค๋ฉด ) =90 ( ๊ฐ’์„ ํ• ๋‹น ) 3. someVaraible์— ๊ฐ’์ด ์žˆ๋‹ค๋ฉด, ๋ณ€์ˆ˜ otherVariable ๊ฐ’ ๋Œ€์ž… ๐Ÿ’กsomeVariable์„ unWrapping ์ „์— ์ถœ๋ ฅํ•ด๋ณธ๋‹ค๋ฉด ? someVariable์ด Optional๋กœ ๊ฐ’์„ ๊ฐ์‹ธ๊ณ  ์žˆ์—ˆ๋Š”๋ฐ, ์ด๋ฅผ ์–ธ๋ž˜ํ•‘ํ•˜์—ฌ ๋ฒ—๊ฒผ๊ธฐ๋•Œ๋ฌธ์— otherVaraible ์—๋Š” ์•Œ๋งน์ด์ธ 90๋งŒ ๋‚˜์˜ค๋Š” ๊ฒƒ์ด๋‹ค.

article thumbnail
[Swift]04 : for๋ฌธ

๐Ÿ“–Day 04 : for ๋ฐ˜๋ณต๋ฌธ ์‚ฌ์šฉ๋ฐฉ๋ฒ•