Deep_Dev
article thumbnail
[Swift] ์™œ Swift์—์„œ ๋ฌธ์ž์—ด์€ index๋กœ ์กฐํšŒํ•˜์ง€ ๋ชปํ• ๊นŒ?

๐Ÿ“š Swift ์—์„œ ๋ฌธ์ž์—ด index ์ ‘๊ทผ์— ๋Œ€ํ•˜์—ฌ Swift ์—์„œ ๋ฌธ์ž์—ด์€ ์–ด๋–ป๊ฒŒ ์กฐํšŒํ• ๊นŒ ? swift์—์„œ ๋ฌธ์ž์—ด์„ ์ •์ˆ˜ index๋กœ ์กฐํšŒํ•˜๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด Swift์—์„œ๋Š” ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ์กฐํšŒํ•ด์•ผ ํ• ๊นŒ ? String.Index๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ ‘๊ทผํ•œ๋‹ค. // ์„ ์–ธ let str = "hello world!" // ์กฐํšŒ str[str.startIndex] // 'h' str[str.endIndex] // '!'๊ฐ€ ๋‚˜์˜ฌ์ง€ ์•Œ์•˜๊ฒ ์ง€๋งŒ ์—๋Ÿฌ ๋ฐœ์ƒ var idx = str.index(str.startIndex, offsetBy: 6) str[idx] // 'w' // ๋ฐ˜๋ณต๋ฌธ์„ ์ธ๋ฑ์Šค์ฒ˜๋Ÿผ ๋ฝ‘์•„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด indicies ๋ฉ”์†Œ๋“œ ์‚ฌ์šฉ for i in str.indices { print(str[i]) // ..

article thumbnail
[Swift] ReplacingOccurrences ( ๋ฌธ์ž์—ด ์น˜ํ™˜ )

๐Ÿ“š ๋ฌธ์ž์—ด ๋‚ด ํŠน์ •๋ฌธ์ž ๋ณ€๊ฒฝ (์น˜ํ™˜) ReplacingOccurrences ๋ฌธ์ž์—ด์„ ๋Œ€์ฒดํ•˜์—ฌ ์ƒˆ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. - of target : ๋ฐ”๊ฟ€ ๋ฌธ์ž์—ด - with replacement : ๋Œ€์ฒดํ•  ๋ฌธ์ž์—ด ์‚ฌ์šฉ์˜ˆ์‹œ let str = "Bye Nice to meet you" let result = str.replacingOccurrences(of: "Bye", with: "Hello") print(result) // "Hello Nice to meet you" of: ์— ์žˆ๋Š” "Bye"๋ฅผ "Hello"๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ์ฝ”๋“œ์ด๋‹ค.

article thumbnail
[Swift] Split , Components

๐Ÿ“š ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ ๋ฉ”์†Œ๋“œ split components Split split๋ฉ”์„œ๋“œ๋Š” ๋‹ค์–‘ํ•œ parameter๋ฅผ ์ง€์›ํ•œ๋‹ค. ๊ฐ๊ฐ์˜ ์—ญํ• ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. - separater : ์ชผ๊ฐœ๋ ค๋Š” ๋ฌธ์ž ๋‹จ์œ„ - maxSplits : ์ง€์ •ํ•œ ๋ฌธ์ž ๋‹จ์œ„๋กœ ์–ผ๋งˆ๋‚˜ ์ชผ๊ฐค์ง€ - omittingEmptySubsequences : Bool๊ฐ’์œผ๋กœ ๊ฒฐ๊ณผ๊ฐ’์—์„œ ๋นˆ ์‹œํ€€์Šค์˜ ํฌํ•จ ์œ ๋ฌด๋ฅผ ์„ค์ • ์ฐธ๊ณ  : https://zeddios.tistory.com/232 split์€ ๋ง ๊ทธ๋Œ€๋กœ ๋ฌธ์ž์—ด์„ ํŠน์ • ๋ฌธ์ž ๊ธฐ์ค€์œผ๋กœ ์ชผ๊ฐค ์ˆ˜ ์žˆ๋‹ค. ๋ฐ˜ํ™˜ํ˜•์€ Stringํƒ€์ž…์„ [Substring]์œผ๋กœ ๋ฐ˜ํ™˜ํ•˜๊ฒŒ ๋œ๋‹ค. ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜๋ฐ›๊ฒŒ ๋˜๋Š” ๊ฒƒ์ด๋‹ค. ๋˜ํ•œ ํ‘œ์ค€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— ๋“ค์–ด๊ฐ€์žˆ๋‹ค. ๋•Œ๋ฌธ์— ๋ฐ”๋กœ import Foundation์„ ํ•  ํ•„์š”์—†์ด ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค. let ..

[Swift] Map, Filter, Reduce

๐Ÿ“š ๊ณ ์ฐจํ•จ์ˆ˜ Map Filter Reduce ๊ณ ์ฐจํ•จ์ˆ˜๋ž€ ? ๋‹ค๋ฅธ ํ•จ์ˆ˜๋ฅผ ์ „๋‹ฌ์ธ์ž๋กœ ๋ฐ›๊ฑฐ๋‚˜ ํ•จ์ˆ˜์‹คํ–‰์˜ ๊ฒฐ๊ณผ๋ฅผ ํ•จ์ˆ˜๋กœ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜ ( = ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ํ•จ์ˆ˜๋ฅผ ๊ฐ–๋Š” ํ•จ์ˆ˜ ) Map ( ๋ณ€ํ˜• ) ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ€ํ˜•ํ•˜๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค. ๊ธฐ์กด ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ€ํ˜•ํ•˜์—ฌ ์ƒˆ๋กœ์šด ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋งŒ๋“œ๋Š”๋ฐ, ๊ธฐ์กด ๋ฐ์ดํ„ฐ๋Š” ๋ณ€ํ˜•๋˜์ง€ ์•Š๋Š”๋‹ค. Map์€ ๊ธฐ์กด์˜ for-in ๊ตฌ๋ฌธ๊ณผ ํฐ ์ฐจ์ด๊ฐ€ ์—†์ง€๋งŒ, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ด์ ์ด ์žˆ๋‹ค. ์ฝ”๋“œ์˜ ๊ฐ„๊ฒฐ์„ฑ ์žฌ์‚ฌ์šฉ ์šฉ์ด ์ปดํŒŒ์ผ๋Ÿฌ ์ตœ์ ํ™” ์„ฑ๋Šฅ ์ข‹์Œ map์˜ ๊ธฐ๋ณธ ํ˜•ํƒœ array.map(transform:T throws -> T) Tํƒ€์ž…์˜ transform์„ ๋ฐ›์•„ ์ƒˆ๋กœ์šด Txใ…์ž…์˜ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค๋Š” ๋ง์ด๋‹ค. * ๊ธฐ์กด for - in ๊ตฌ๋ฌธ let numArray = [1,3,5,7,9] var multiArra..

article thumbnail
[Swift] prefix suffix

๐Ÿ“š prefix suffix prefix ์ปฌ๋ ‰์…˜์˜ ์ดˆ๊ธฐ ์š”์†Œ๋ฅผ ํฌํ•จํ•˜๋Š” ์ง€์ •๋œ ์ตœ๋Œ€ ๊ธธ์ด๊นŒ์ง€ ํ•˜์œ„ ์‹œํ€€์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ์ตœ๋Œ€ ๊ธธ์ด๊ฐ€ ์š”์†Œ ์ˆ˜๋ฅผ ์ดˆ๊ณผํ•˜๋Š” ๊ฒฝ์šฐ ๊ฒฐ๊ณผ์—๋Š” ์ปฌ๋ ‰์…˜์˜ ๋ชจ๋“  ์š”์†Œ๊ฐ€ ํฌํ•จ๋œ๋‹ค. let numbers = [1, 2, 3, 4, 5] print(numbers.prefix(2)) // Prints "[1, 2]" print(numbers.prefix(10)) // Prints "[1, 2, 3, 4, 5]" ๊ด€๋ จ ๋ฌธ์ œ prefix ๋ฅผ ์ด์šฉํ•˜์—ฌ ํ‘ผ๋‹ค๋ฉด ? import Foundation func solution(_ my_string:String, _ n:Int) -> String { return String(my_string.prefix(n)) } ๐Ÿ’ก my_string:prefix(n) ์•ž์—..

article thumbnail
[Swift] String ๋‹ค์–‘ํ•œ ํ•จ์ˆ˜ ์ •๋ฆฌ

๐Ÿ“š String ๊ตฌ์กฐ์ฒด์ด๊ณ  ๋‹ค๋ฅธ ์–ธ์–ด์™€ ๊ฐ™์ด character๊ฐ€ ๋ชจ์ธ ์ง‘ํ•ฉ Array() : ๋ฌธ์ž์—ด -> ๋ฐฐ์—ด ๋ฌธ์ž์—ด์˜ ์š”์†Œ ํ•˜๋‚˜ํ•˜๋‚˜๋ฅผ ๋ฐฐ์—ด๋กœ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•. let name: String = "SWIFT" let arrName = Array(name) print(arrName) // ["S","W","I","F","T"] count() , empty() : ๋ฌธ์ž์—ด์˜ ๊ธธ์ด ๊ตฌํ•˜๊ธฐ let string: "A Unicode string value that is a collection of characters." print(string.count) // 58 let empty = "" print(empty.isEmpty) // true print(string.isEmpty) // false append() : ..

[Swift] ๋ฐฐ์—ด ๋ฉ”์†Œ๋“œ sort() sorted() / reverse() reversed()

๐Ÿ“š ๋ฐฐ์—ด์˜ ๋‹ค์–‘ํ•œ ๋ฉ”์†Œ๋“œ ์ •๋ ฌ sort() sorted() sort()๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ '์›๋ณธ ๋ฐฐ์—ด'์„ ๊ฐ€์ง€๊ณ  ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ์„ ํ•œ๋‹ค. ๋ฌผ๋ก  ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ๋„ ์ •๋ ฌ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. ๋งŒ์•ฝ, ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ์„ ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด, sort(by:)๋ฅผ ์‚ฌ์šฉํ•ด์„œ sort(by:>)์™€ ๊ฐ™์ด ์ž‘์„ฑํ•ด์ฃผ๋ฉด ๋œ๋‹ค. sort(by:)๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ๋‹ค. ๋ฐ”๋กœ sort(by:)๋กœ ์ž‘์„ฑํ•ด์ฃผ๋ฉด ๋œ๋‹ค. sort์™€ ๋™์ผํ•˜๊ฒŒ sorted()๋งŒ ์ž‘์„ฑํ•ด์ฃผ๋ฉด ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ๋œ๋‹ค. ์ฝ”๋“œ์˜ˆ์‹œ var arr = [ 1, 5, 2, 4, 3 ] // ๊ธฐ๋ณธ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ var sotredArr = arr.sorted() print(arr) // [1, 5, 2, 4, 3] print(sortedArr) // [1, 2, 3, 4,..

article thumbnail
[iOS] ์•ฑ์˜ ์ƒ๋ช…์ฃผ๊ธฐ (LifeCycle)
๐ŸŽ iOS/UIKit 2023. 6. 15. 16:03

์ƒ๋ช…์ฃผ๊ธฐ ( LifeCycle ) ์ƒ๋ช…์ฃผ๊ธฐ๋ผ๋Š” ๊ฒƒ์€ ์•ฑ์˜ ์ตœ์ดˆ ์‹คํ–‰๋ถ€ํ„ฐ ์•ฑ์ด ์™„์ „ํžˆ ์ข…๋ฃŒ๋˜๊ธฐ๊นŒ์ง€ ์•ฑ์ด ๊ฐ€์ง€๋Š” ์ƒํƒœ์™€ ๊ทธ ์ƒํƒœ๋“ค ์‚ฌ์ด์˜ ์ „์ด๋ฅผ ๋งํ•œ๋‹ค. ์•ฑ์˜ ์ƒํƒœ๋Š” ์•ฑ์ด ํ˜„์žฌ ์–ด๋– ํ•œ ๊ฒƒ์„ ํ•  ์ˆ˜ ์žˆ๋Š”๊ฐ€๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค. ์•ฑ์˜ ์ƒ๋ช…์ฃผ๊ธฐ ( App's Life Cycle ) App์˜ ์ƒ๋ช…์ฃผ๊ธฐ๋Š” APP์˜ ์‹คํ–‰/์ข…๋ฃŒ ๋ฐ App์ด Foreground/Background ์ƒํƒœ์— ์žˆ์„ ๋•Œ, ์‹œ์Šคํ…œ์ด ๋ฐœ์ƒ์‹œํ‚ค๋Š” event์— ์˜ํ•ด App์˜ ์ƒํƒœ๊ฐ€ ์ „ํ™˜๋˜๋Š” ๊ณผ์ •์„ ๋งํ•œ๋‹ค. ์นด์นด์˜คํ†ก ์•ฑ์œผ๋กœ ์นดํ†ก์„ ํ•˜๊ณ  ์žˆ๋Š” ๋„์ค‘์— ์ „ํ™”๊ฐ€ ์™”์„ ๋•Œ ์•ฑ์ด ํ™”๋ฉด์ƒ์—์„œ ๋ณด์—ฌ์ง€์ง€ ์•Š๋Š” ์ƒํƒœ์ธ Background ์ƒํƒœ์™€ ์•ฑ์ด ํ™”๋ฉด์— ์˜ฌ๋ผ์™€์žˆ๋Š” ์ƒํƒœ์ธ Foreground ๋“ฑ๊ณผ ๊ฐ™์€ ์ƒํƒœ๋“ค์„ ์ •์˜ํ•œ ๊ฒƒ์ด๋‹ค. iOS์—์„œ ์•ฑ์„ ์‹คํ–‰ํ•˜๋ฉด ๋ฌด์Šจ ์ผ์ด ๋ฒŒ์–ด์งˆ๊นŒ ? iO..