Вы можете пойти с кортежами
let interestingNumbers = ["prime": [2,3,5,7,11,13], "fibonacci": [1,1,2,3,5,8], "square": [1,4,9,16,25]]
var largest:(key:String, number:Int) = ("",0);
var secondLargest:(key:String, number:Int) = ("",0)
for (kind, numbers) in interestingNumbers{
for number in numbers {
if number>largest.number {
secondLargest = (kind,largest)
largest = (kind, number)
} else if (number > secondLargest.number && number != largest.number) {
secondLargest= (kind,number)
}
}
}
print( "The largest number is: \(largest.number) ")
print( "The second largest number is: \(secondLargest.number) and is a\(secondLargest.key)
kind ")