나의 발자취

튜플 특징 본문

앱 개발/iOS

튜플 특징

달모드 2023. 6. 28. 01:08

 

var easyAsPie = ("easy as", 3.14)

Above, we created easyAsPie that holds 2 values: "easy as", and 3.14. If we wanted to access each value individually, we can use dot syntax along with the index of the value:

var easyAsPie = ("easy as", 3.14)
var firstValueeasyAsPie.0   // "easy as"
var secondValueeasyAsPie.1  // 3.14

We can also name a tuple’s elements by prepending each one with a name and a colon - similar to key-value pair syntax in dictionaries:

var easyAsPie = (saying: "easy as", amount: 3.14)
var firstElementValueeasyAsPie.saying  // "easy as"
var secondElementValueeasyAsPie.amount // 3.14

출처:codecademy

'앱 개발 > iOS' 카테고리의 다른 글

Swift 함수 한번에 정리  (0) 2023.06.30
if-let 구문, 옵셔널 바인딩  (0) 2023.06.28
View: Vstack, Hstack, Zstack  (0) 2023.06.20
SwiftUI View란? View Modifiers  (0) 2023.06.20
Switch Statement: Where clause  (0) 2023.06.20
Comments