For Loop in Apple Swift

前端 未结 5 2048
眼角桃花
眼角桃花 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条回答
  •  情话喂你
    2021-02-14 03:51

    However, I can't seem to figure out what is "(kind,numbers)" here represent

    The loop iterates over the dictionary, and every iteration gives you a key and associated value. Those are called kind (key) and numbers (value) here. You can choose any name you want.

    and how should I make my for-loop to go through all Dictionary(interestingNumbers) keys and find which key has the largest number.

    You get each key in turn in the kind loop variable.

    Once you find one that results in a new largest, you can assign that to a result variable, say largestKind.

    At the end of the loop, largestKind will contain the key of the array with the largest number (that number being the largest you already have).

提交回复
热议问题