For Loop in Apple Swift

前端 未结 5 2061
眼角桃花
眼角桃花 2021-02-14 03:24

Apple\'s newly released language Swift has an example on the official documentation. Example is like this;

let interestingNumbers = [
    \"Prime\": [2, 3, 5, 7,         


        
5条回答
  •  Happy的楠姐
    2021-02-14 03:27

    let interestingNumbers = [
        "Prime": [2, 3, 5, 7, 11, 13],
        "Fibonacci": [1, 1, 2, 3, 5, 8],
        "Square": [1, 4, 9, 16, 25],
    ]
    var largest = 0
    for (kind, numbers) in interestingNumbers {
        for number in numbers {
            if number > largest {
                largest = number
            }
        }
    }
    largest
    

    This will return pair of (String,Int) which we have in Our Dictionary similar to function return multiple value as below,

       func refreshWebPage() -> (status:String,code:Int){
        //refresh logic
                    return ("Success",200)
        }
    

提交回复
热议问题