四、Swift Function練習:歌曲Sam Smith –How Do You Sleep?和Jung kook–Seven

Yenci
彼得潘的 Swift iOS / Flutter App 開發教室
7 min readAug 11, 2023

我不太喜歡聽悲傷的情歌(除非我聽不懂)

作業內容:

  1. 印歌詞。找出重覆的段落,定義 function。
  2. 定義有參數的 function,傳入字串修改歌詞。

題目來源:
Develop in Swift Explorations 裡 Unit 2 的 Functions.playground,page 11 & 12 的 Functional Meme。

因為作業另一個內容是要用參數換歌詞,我想到了Jungkook Seven這首有兩個版本歌詞的歌,這樣我就不用自己想要換什麼歌詞,還可以偷渡不悲傷的歌,豪聰明,要五毛給一塊。

我喜歡的歌手跟歌曲

Sam Smith –How Do You Sleep?

發現山姆的歌詞沒那麼多重複的地方,只有副歌重複而已。用心喔山姆。


func verse1() {
print("I'm done hatin' myself for feelin'")
print("I'm done cryin' myself awake")
print("I gotta leave and start the healin'")
print("But when you move like that, I just wanna stay")
}

func preChorus() {
print("What have I become now?")
print("Lookin' through your phone now")
print("Oh now, love to you is just a game")
print("Look what I have done now")
print("Dialling up the numbers on you")
print("I don't want my heart to break")
}

func chorus() {
print("Baby, how do you sleep when you lie to me?")
print("All that shame and all that danger")
print("I'm hopin' that my love will keep you up tonight")
print("Baby, how do you sleep when you lie to me?")
print("All that fear and all that pressure")
print("I'm hopin' that my love will keep you up tonight")
}

func postChorus() {
print("Tell me, how do you-")
print("Love will keep you up tonight")
print("Tell me, how do you-")

}
func verse2() {
print("Oh, no, how did I manage to lose me?")
print("I am not this desperate, not this crazy")
print("There's no way I'm stickin' 'round to find out")
print("I won't lose like that, I won't lose myself")
}

func preChorus2() {
print("Look what I have done (Done)")
print("Diallin' up the numbers on you")
print("I don't want my heart to break")
}

func postChorus2() {
print("Tell me, how do you-")
print("Yeah, yeah, yeah")
print("Love will keep you up tonight")
print("Tell me, how do you-)")
print("Oh, love will keep you up tonight")
}

verse1()
preChorus()
chorus()
postChorus()
verse2()
preChorus2()
chorus()
postChorus2()
chorus()

compile一下:

上次傳How Do You Sleep?的歌給朋友,朋友開玩笑回說他都側睡。

Jung kook–Seven

一一對照了 Clean跟Explicit兩個版本的差別,用心做填空。

還要想一下參數名稱。在這過程中了解到為什麼大家說想變數名很難。

func seven (who: String, verb: String) {

print("It's the way that \(who) can ride")
print("It's the way that \(who) can ride")
print("Think I met you in another life")
print("So break me off another time")
print("You wrap around me and you give me life")
print("And that's why night after night")
print("I'll be \(verb) you right")
print("Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday (A week)")
print("Monday, Tuesday, Wednesday, Thursday, Friday")
print("Seven days a week")
print("Every hour, every minute, every second")
print("You know night after night")
print("I'll be \(verb) you right")
print("Seven days a week")

}

seven(who:"you", verb: "love")

compile一下:

必須得聽一下歌的吧:

剛剛點進去看了一下,本來不知道這首歌有編舞XDD酷喔Sam

--

--