Swift - Dictionaries

Aus Wikizone
Wechseln zu: Navigation, Suche

Links[Bearbeiten]

Swift

Beispiele[Bearbeiten]

import UIKit

studentsAndScores["Max"] = 65
print("Number of students: \(studentsAndScores.count)")
print("Keys: \(studentsAndScores.keys) - note that the order is different each time")
showScores(scores:studentsAndScores)
print("James Score is: \(studentsAndScores["James"]!)")
highestScore(scores: studentsAndScores)

func showScores(scores: [String: Int]){
    for score in scores {
        print(" \(score.key) \(score.value)")
    }
}

func highestScore(scores: [String: Int]) {
    var highest = scores.values.max()
    print(highest ?? 0)
}