๊ณต๋ถ€ ์—ฐ์Šต์žฅ :-)

TIL_20171102

|

์˜ค๋Š˜ ๊ณต๋ถ€ํ•œ / ๋Š๋‚€ ๊ฒƒ

  • ์‚ฌ๋‹ค๋ฆฌ๊ฒŒ์ž„ step1 PR > merge ํ†ต๊ณผ!
  • Git ํ˜‘์—… - โ€œ๊ฐœ๋ฐœ ๋ธŒ๋žœ์น˜์—์„œ ์ž‘์—…ํ•˜๊ณ  PR, ์ฝ”๋ฉ˜ํŠธ๋กœ ์ฝ”๋“œ๋ฆฌ๋ทฐ ๋ฐ›๊ณ  merge์ดํ›„ ๋‚ด ๋กœ์ปฌ๊ณผ ๋ฆฌ๋ชจํŠธ ๋ธŒ๋žœ์น˜ ๊ฐ„ ์‹ฑํฌ๋ฅผ ๋งž์ถ”๊ณ  ์ƒˆ ๋ธŒ๋žœ์น˜์— ์ž‘์—…์„ ์‹œ์ž‘โ€ ํ•˜๋Š” ๊ฒƒ ๊นŒ์ง€ ํ•œ circle์„ ๋Œ์•˜๋‹ค.
    • ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ• ๋•Œ ๋ฒ„์ „๊ด€๋ฆฌ์‹œ์Šคํ…œ์—์„œ ๋งค์šฐ๋งค์šฐ๋งค์šฐ์ค‘์š”ํ•จ.
    • ์ƒˆ๋กญ๊ฒŒ merge๋œ ๋ถ€๋ถ„์ด ์žˆ์œผ๋ฉด ๋ฐ˜๋“œ์‹œ fetch / rebase๋กœ sync๋ฅผ ๋งž์ถฐ๋†“๊ณ  ์ง„ํ–‰ํ•˜๊ธฐ!
    • ์ต์ˆ™ํ•ด์ง€๊ธฐ ์ „๊นŒ์ง„ ์ œ๋Œ€๋กœ ํ•˜๊ณ  ์žˆ๋Š”์ง€ ๋‹จ๊ณ„๋งˆ๋‹ค ํ™•์ธํ•˜๊ธฐ!
  • ์‚ฌ๋‹ค๋ฆฌ ๊ฒŒ์ž„ step2 - 2์ค‘ ๋ฐ˜๋ณต๋ฌธ depth์ค„์ด๊ธฐ
  • ํ•จ์ˆ˜ / ํด๋กœ์ € - ๊ผผ๊ผผํ•œ ์žฌ์€์”จ์˜ ์Šค์œ„ํ”„ํŠธ ๋ณด๊ณ  ์ •๋ฆฌ

์•ž์œผ๋กœ ํ•  ๊ฒƒ

  • ์‚ฌ๋‹ค๋ฆฌ ๊ฒŒ์ž„ step2 : guard ์“ฐ๊ธฐ- if / else์—์„œ else๋ฅผ ์“ฐ์ง€ ์•Š๊ธฐ
  • ๋‹ค์Œ ๋ฏธ์…˜์„ ์ง„ํ–‰ํ•˜๋ฉด์„œ ์ŠคํŠธ๋ŸญํŠธ / ํด๋ž˜์Šค ์ ์šฉํ•ด๋ณด๊ธฐ

์Šค์œ„ํ”„ํŠธ์˜ "ํ•จ์ˆ˜"

|

ํ•จ์ˆ˜

Parameter

์™ธ๋ถ€ ํŒŒ๋ผ๋ฏธํ„ฐ / ๋‚ด๋ถ€ ํŒŒ๋ผ๋ฏธํ„ฐ

ํ•จ์ˆ˜์˜ ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด์„œ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ์˜ ์ด๋ฆ„๊ณผ ํ•จ์ˆ˜ ์•ˆ์— ๊ตฌํ˜„๋œ ํŒŒ๋ผ๋ฏธํ„ฐ์˜ ์ด๋ฆ„์ด ๋‹ค๋ฅด๋‹ค.

์•„๋ž˜๋Š” ์™ธ๋ถ€ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ๊ฐ€๋…์„ฑ์„ ๋†’์ผ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๋ ค์ฃผ๋Š” ์˜ˆ์ œ, ๊ตฌ์–ด์ฒ˜๋Ÿผ ์ „์น˜์‚ฌ to๋ฅผ ์™ธ๋ถ€ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์‚ฌ์šฉํ–ˆ๋‹ค.

func ํ•จ์ˆ˜๋ช… (์™ธ๋ถ€ํŒŒ๋ผ๋ฏธํ„ฐ ๋‚ด๋ถ€ํŒŒ๋ผ๋ฏธํ„ฐ: ํƒ€์ž…){}
func printGreeting(to name: String){
  print("Hello \(name), welcome!")
}

// ํ•จ์ˆ˜ํ˜ธ์ถœ
printGreeting(to: "Aliens")

๊ฐ€๋ณ€์ธ์ž

๋ณดํ†ต ํ•จ์ˆ˜๋Š” ๋ฏธ๋ฆฌ ์ •์˜๋œ ํ˜•์‹๊ณผ ๊ฐœ์ˆ˜์— ๋งž๋Š” ์ธ์ž๊ฐ’๋งŒ ์ฒ˜๋ฆฌํ•˜์ง€๋งŒ, ์Šค์œ„ํ”„ํŠธ์—์„œ๋Š” ํ•จ์ˆ˜๊ฐ€ ๊ฐ€๋ณ€์ ์ธ ๊ฐœ์ˆ˜์˜ ์ธ์ž๊ฐ’์„ ์ž…๋ ฅ๋ฐ›์„ ์ˆ˜ ์žˆ๋„๋ก ์ง€์›ํ•œ๋‹ค.

์•„๋ž˜์™€ ๊ฐ™์ด ๋งค๊ฐœ๋ณ€์ˆ˜ ํƒ€์ž…์— โ€œโ€ฆโ€์„ ์ ์–ด์ฃผ๋ฉด ๊ฐ€๋ณ€์ธ์ž๋กœ ์ธ์‹๋˜์–ด ๊ฐœ์ˆ˜๋ฅผ ์ œํ•œํ•˜์ง€ ์•Š๊ณ  ์ธ์ž๊ฐ’์„ ์ž…๋ ฅ๋ฐ›๊ณ , ์ž…๋ ฅ๋ฐ›์€ ์ธ์ž๊ฐ’์€ ๋ฐฐ์—ด์— ์ €์žฅํ•œ๋‹ค!

func ํ•จ์ˆ˜์ด๋ฆ„(๋งค๊ฐœ๋ณ€์ˆ˜๋ช… : ๋งค๊ฐœ๋ณ€์ˆ˜ ํƒ€์ž… ...)
func average(score: Int...) -> Double {
  var total = 0
  for r in score {
    total += r
  }
  return (Double(total)/Double(score.count))
}

average(score: 10,20,30,40)
func printGreeting(to all: String...){
  for name in all{
    print("Hello \(name), welcome!")
  }
}
printGreeting(to: "Woody","Buzz","Aliens","Mr.Potato Head"

/*
๊ฒฐ๊ณผ:
Hello Woody, welcome!
Hello Buzz, welcome!
Hello Aliens, welcome!
Hello Mr.Potato Head, welcome!              
*/              
              

๊ธฐ๋ณธ๊ฐ’์„ ๊ฐ–๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜

ํ•จ์ˆ˜์˜ ์ •์˜ ์‹œ ๋งค๊ฐœ๋ณ€์ˆ˜์— ๊ธฐ๋ณธ๊ฐ’์„ ์ง€์ •ํ•˜๋ฉด ํ•ด๋‹น ํ•จ์ˆ˜ ํ˜ธ์ถœ ์‹œ ์ธ์ž๊ฐ’์„ ์ƒ๋žตํ•  ์ˆ˜ ์žˆ๋‹ค. ์ƒ๋žตํ•˜๋ฉด ๊ธฐ๋ณธ๊ฐ’์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌ๋˜์–ด ํ•จ์ˆ˜๊ฐ€ ์‹คํ–‰๋˜๊ณ , ํ•จ์ˆ˜ ํ˜ธ์ถœ ์‹œ ๊ธฐ๋ณธ๊ฐ’์ด ์ •ํ•ด์ง„ ํŒŒ๋ผ๋ฏธํ„ฐ์— ์ƒˆ๋กœ ๊ฐ’์„ ์ฃผ๊ฒŒ๋˜๋ฉด ์ƒˆ๋กœ ์ฃผ์–ด์ง„ ๊ฐ’์ด ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์ „๋‹ฌ๋˜์–ด ํ•จ์ˆ˜๊ฐ€ ์‹คํ–‰๋œ๋‹ค. (๋”ฐ๋ผ์„œ ๋งค๊ฐœ๋ณ€์ˆ˜์— ๊ธฐ๋ณธ๊ฐ’์„ ์ฃผ๋ฉด ํ•จ์ˆ˜๋Š” ๋‘ ๊ฐ€์ง€ ํ˜•์‹ - ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ๋™์ž‘ / ์ƒˆ๋กœ ๋„˜๊ฒจ์ฃผ๋Š” ๊ฐ’์œผ๋กœ ๋™์ž‘ - ์œผ๋กœ ๋ชจ๋‘ ์ƒ์„ฑ๋œ๋‹ค๊ณ  ํ•  ์ˆ˜ ์žˆ๋‹ค.

func ํ•จ์ˆ˜์ด๋ฆ„(๋งค๊ฐœ๋ณ€์ˆ˜: ๋งค๊ฐœ๋ณ€์ˆ˜ ํƒ€์ž… = ๊ธฐ๋ณธ๊ฐ’){
  ์‹คํ–‰ํ•  ๋‚ด์šฉ
}
func divideNum(numerator: Double, denominator: Double, withPunctuation punctuation: String = "^_^"){
    print("\(numerator)/\(denominator) equals \(numerator/denominator)\(punctuation)")
}

divideNum(numerator: 9.0, denominator: 3.0)
divideNum(numerator: 9.0, denominator: 3.0, withPunctuation: "!")

/*
๊ฒฐ๊ณผ : punctuation๋ถ€๋ถ„์ด ๋‹ฌ๋ผ์ง
9.0/3.0 equals 3.0^_^
9.0/3.0 equals 3.0!
*/

์ธ์•„์›ƒ ํŒŒ๋ผ๋ฏธํ„ฐ

var error = "The request failed:"
func appendErrorCode(_ code: Int, toErrorString errorString: inout String){
    if code == 400 {
        errorString += "bad request."
    }
}

appendErrorCode(400, toErrorString: &error)

//The request failed: bad request.

๋ณต์ˆ˜ ๋ฆฌํ„ด๊ฐ’ - ํŠœํ”Œ ์‚ฌ์šฉํ•˜๊ธฐ ์˜ˆ์ œ

func sortedEvenOddNumbers(_ numbers: [Int]) -> (evens: [Int], odds: [Int]){
    var evens = [Int]()
    var odds = [Int]()
    for number in numbers {
        if number % 2 == 0{
            evens.append(number)
        } else {
            odds.append(number)
        }
    }
    return (evens, odds)
}

let aBunchOfNumbers = [10,1,3,55,66,78,93,103]
let theSortedNumbers = sortedEvenOddNumbers(aBunchOfNumbers)
print ("Even numbers: \(theSortedNumbers.evens)")
print ("Odd numbers: \(theSortedNumbers.odds)")

TIL_20171101

|

์˜ค๋Š˜ ๊ณต๋ถ€ํ•œ / ๋Š๋‚€ ๊ฒƒ

  • ์˜ค๋Š˜์€ ๊ฑฐ์˜ ๊ผฌ์ธ ๊นƒ ๋ธŒ๋žœ์น˜๋ฅผ ํ•ด๊ฒฐํ•˜๋Š”๋ฐ ์‹œ๊ฐ„์„ ๋ณด๋ƒˆ๋‹คโ€ฆ

    ( ๊ทธ ๋•์— ํ„ฐ๋ฏธ๋„๊ณผ ์กฐ๊ธˆ ์นœํ•ด์กŒ๋‹ค! ํ•˜ํ•˜โ€ฆ)

  • ์ฝ”๋“œ์Šค์ฟผ๋“œ์˜ ์ „ ๋ฉค๋ฒ„๊ฐ€ ํ•œ๋ฒˆ์”ฉ ์ž๊ธฐ์†Œ๊ฐœํ•˜๋Š” ์‹œ๊ฐ„์„ ๊ฐ€์กŒ๋Š”๋ฐ ์ •๋ง ๋‹ค์–‘ํ•˜๊ณ , ์—๋„ˆ์ง€๊ฐ€ ๋ฐ๊ณ , ๊ธ์ •์ ์ธ ๋ถ„๋“ค์ด ๋งŽ์€ ๊ฒƒ ๊ฐ™๋‹ค. ์˜ค๋žœ๋งŒ์— ์ด๋Ÿฐ ๊ทธ๋ฃน(?)์— ์†ํ•ด์žˆ๋Š” ๊ธฐ๋ถ„์ธ๋ฐ ๋‚˜๊นŒ์ง€ ๊ธ์ •์ ์ธ ์—๋„ˆ์ง€๋ฅผ ๋ฐ›๋Š” ๊ฒƒ ๊ฐ™์•„ ์ข‹๋‹ค :-)

์•ž์œผ๋กœ ํ•  ๊ฒƒ

  • ์Šค์œ„ํ”„ํŠธ ๊ธฐ๋ณธ - ์ค‘๊ธ‰ ๋ฌธ๋ฒ• ํ•˜๋ฃจ ํ•˜๋‚˜์”ฉ ์ตํžˆ๊ธฐ
  • PR - mergeํ›„์—” ๊ผญ fetch / rebase๋ฅผ ํ•ด์„œ sync๋ฅผ ๋งž์ถ”์žโ€ฆ

TIL_20171031

|

์˜ค๋Š˜ ๋ฐฐ์šด / ๋Š๋‚€ ๊ฒƒ

  • ์‚ฌ๋‹ค๋ฆฌ๊ฒŒ์ž„ ์ฒซ ์š”๊ตฌ์‚ฌํ•ญ PR
  • Git ๋ธŒ๋žœ์น˜๋ฅผ ๋‚˜๋ˆ„๊ณ  ์ž‘์—…ํ• ๋•Œ ๊ผญ ๊ทธ ์ „์˜ status๋ฅผ ํ™•์ธํ•ด์„œ fetch/rebase๋ฅผ ํ•ด์•ผํ•จ!
  • struct, class๊ณต๋ถ€ : ๋น… ๋„ˆ๋“œ๋žœ์น˜ monster / zombie ํƒ€์šด
  • Git ๋ฒ„์ „๊ด€๋ฆฌ์‹œ์Šคํ…œ ๋ธŒ๋žœ์น˜ ๋‚˜๋ˆ„๊ณ  ์ž‘์—…, sync๋งž์ถ”๋Š” ๊ณผ์ • ์‹ค์Šต

์•ž์œผ๋กœ ํ•  ๊ฒƒ

  • ์‚ฌ๋‹ค๋ฆฌ๊ฒŒ์ž„ ๋ฏธ์…˜์„ ์ •ํ•ด์ง„ ๋ชฉํ‘œ์— ๋งž๊ฒŒ ์ง„ํ–‰ํ•˜๊ธฐ!
    • ํ•˜๋ฃจ ํ•˜๋‚˜์”ฉ PR, 1์ฃผ์ผ ~ 1.5์ฃผ์ผ ๋‚ด๋กœ ์™„๋ฃŒ
  • ์Šค์œ„ํ”„ํŠธ๋ฌธ๋ฒ• : โ€œํ•จ์ˆ˜โ€ ๊ณต๋ถ€

TIL_20171030

|

์˜ค๋Š˜ ๋ฐฐ์šด / ๋Š๋‚€ ๊ฒƒ

  • ๋‹จ์œ„๋ณ€ํ™˜๊ธฐ : ๋”•์…”๋„ˆ๋ฆฌ์™€ switch - case๋ฅผ ํ†ตํ•ด ๊ณ„์‚ฐ๋ถ€๋ถ„ ๋กœ์ง ์ค„์ž„ (๋‹จ์œ„ ์ข…๋ฅ˜๋งˆ๋‹ค ๋‹ค๋ฅธ ๋กœ์ง์ด ์•„๋‹ˆ๋ผ ๊ฐ™์€ ๋กœ์ง์œผ๋กœ ์ฒ˜๋ฆฌ๋˜๋„๋ก ์ˆ˜์ •)
  • ํ•จ์ˆ˜ ์ค‘์‹ฌ ํ”„๋กœ๊ทธ๋ž˜๋ฐ
  • ํด๋กœ์ € / ์ถ”์ƒํ™”

์•ž์œผ๋กœ ํ•  ๊ฒƒ

  • ์ฝ”๋“œ์Šค์ฟผ๋“œ ์ฒซ ์ฃผ์— ๋น„ํ•ด ๋„ˆ๋ฌด ๋Š˜์–ด์ง€๋Š” ๊ฒƒ ๊ฐ™๋‹ค. ๋ชฉํ‘œ๋ฅผ ์ •ํ•ด์„œ ํ•ด์•ผ๊ฒ ๋‹ค.
    • ๊ฐ ๋ฏธ์…˜๋“ค : ์ผ์ฃผ์ผ์— ํ•˜๋‚˜์”ฉ ๋๋‚ด๊ธฐ (์ ์–ด๋„ 1.5์ฃผ ์•ˆ์— ์™„๋ฃŒ)
    • ํ•˜๋ฃจ์— ๊ผญ PRํ•˜๋‚˜
  • ํ•˜๋ฃจ์— ํ•˜๋‚˜์”ฉ ๊ผญ ์Šค์œ„ํ”„ํŠธ ๋ฌธ๋ฒ• / ๊ณ ๊ธ‰๊ฐœ๋… ์ตํžˆ๊ธฐ (๋งค์ผ ์ €๋…์ด๋‚˜ ์•„์นจ์— ์˜ค๋Š˜ ํ•ด์•ผํ•  ๋ฌธ๋ฒ• ๊ฐœ๋… ์ •ํ•ด๋†“๊ธฐ)
  • ๋งค์ผ๋งค์ผ(ํ‰์ผ!) TIL๋น ์ง์—†์ด ์ž‘์„ฑํ•˜๊ธฐ
  • ์ฃผ๋ง์€ ์ผ์ฃผ์ผ์„ ํšŒ๊ณ ํ•˜๊ณ  ๋ถ€์กฑํ–ˆ๋˜ ๋ถ€๋ถ„์„ ์—ฌ์œ ์žˆ๊ฒŒ ๋˜์งš๊ธฐ, ๋„์›€ ๋  ๋งŒํ•œ ์ฑ… ์ฝ๊ณ , ์ปจ๋””์…˜ ์กฐ์ ˆํ•˜๊ธฐ!