๐ ์ฐธ๊ณ
* [<https://docs.swift.org/swift-book/ReferenceManual/Types.html#grammar_tuple-type-element>](<https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html>)
* [<https://zeddios.tistory.com/238>](<https://zeddios.tistory.com/238>)
* [<https://www.hackingwithswift.com/search/tuple>](<https://www.hackingwithswift.com/search/tuple>)
Objective-C ์๋ ์์๋, Swift์์ ์๊ฐ๋ ์๋ก์ด ํ์ .
(val1, val2, val3)
๊ทธ๋ฃน ์์ ๊ฐ**member**๋ค์ ๋ค์ํ ํ์
์ด ๋ค์ด๊ฐ ์ ์๊ณ , **tuple** ์ญ์ ๋ฉค๋ฒ๊ฐ ๋ ์ ์๋ค.
:named type, compound type, function type
๊ฐ ๋ฉค๋ฒ๋ค์ ์ ๊ทผํ๋ ค๋ฉด
.Index
๋ฅผ ์ด์ฉํ๋ค.
๊ฐ ๋ฉค๋ฒ๋ค์ ๋ํด์๋ ์ด๋ฆ์ ์ค ์ ์๋ค.
โ .element's name
์ผ๋ก ์ ๊ทผํ ์ ์๋ค.
let someTuple = (22, true, "์คํธ๋ง")
someTuple.0 //22
someTuple.1 //true
someTuple.2 //"์คํธ๋ง"
let otherTuple = (22, (true, "์คํธ๋ง"))
otherTuple.1 //(.0 true, .1 "์คํธ๋ง")
otherTuple.1.1 //"์คํธ๋ง"
func calculateAdd() {}
func changedMenu() {}
let functionInTuple = (calculateAdd(), changedMenu())
var userData = (height: 170, weight: 65)
userData.height //170
userData.weight //65
userData.height = 180
userData.weight = 60
userData //(height 180, weight 60)
Tuple์ ํจ์์ return๊ฐ์ด ๋ ์ ์๋ค.
(์ผ๋ฐ์ ์ผ๋ก ์ด๋ ๊ฒ, ํจ์๋ก ๋ถํฐ ๋ค์ํ ๊ฐ์ ๋ฐํํ ๋ ์ฌ์ฉ๋๋ค)
func userProfile() -> (name: String, hegiht: Int, weight: Int) {
return ("yooga", 170, 65)
}
userProfile() //(name "yooga", hegiht 170, weight 65)
tuple์ ์์ดํ ์ ์ถ๊ฐํ๊ฑฐ๋ ์ง์ธ ์ ์๋ค.
ํ ๋ฒ ์ ์ธ๋ tuple ๋ฉค๋ฒ์ **ํ์
**์ ๋ฐ๊ฟ ์ ์๋ค.
var userData = (height: 170, weight: 65)
userData = (155, 50)
userData = ("yooga", 50) // ์๋๋ค!
typealias
: ํ์
์ ๋ถ๋ฅผ ๋์ฒด์ด๋ฅผ ๋ง๋ค์ด ์ฃผ๋ ๊ฒ.