Ich habe gerade angefangen zu lernen schnell aus "The Swift Programmiersprache (Swift 3 beta)". Ich bin auf eine Funktion gestoßen, die Tupel-Return-Typ hat. Sie haben es nicht vollständig erklärt. Hier nimmt func "calculateStatistics" ein "score" -Array vom Int-Typ und es hat eine Tupelverbindung als Rückgabetyp. Jetzt, am Ende, wenn sie es mit print-Anweisung aufrufen, verstehe ich nicht, was mit "print (statistics.2)" gemeint ist. Was ".2" bedeutet und wie es berechnet wird.Verstehen schneller Code Tupel Verbindung in einer Funktion
func calculateStatistics(scores : [Int]) -> (min: Int , max: Int , sum: Int)
{
var min = scores[0]
var max = scores[0]
var sum = 0
for score in scores {
if score > max
{
max = score
}else if score < min{
min = score
}
sum += score
}
return (min, max, sum)
}
let statistics = calculateStatistics([5 , 3, 100, 3, 9])
print (statistics.sum)
print (statistics.2)
Vielen Dank. – WasimSafdar
Gern geschehen. –