Swift function with a function as parameter -


I have a question that gives me a compilation error of "missing return in function"? I am following the examples in the book "The Swift Programming Language" and there is a section about passing the function as the parameter of any other function.

Here is an example of a book that just compiles:

  is aunty mats (list: [int], condition: int -> gt; - gt; ; Bull {for the item in the list {status (item) {// mismatched function call returns true}} return false} func lessThanTen (number: int) - & gt; Bull {Return number & lt; 10}  

I understand this, but I thought I could make a subtle change, because I felt that the condition (object) {} was unnecessary. Here's my change:

  func hasAnyMatches (list: [Int], condition: int -> Bool) - & gt; I am coming back because I am returning to the outcome of the ceremony is not such a case, where I will not return a bull during the loop.  

I do not understand why this is not compiled, can anyone explain why?

First of all, your changes do not replace the old code. Your version gives the result of testing the first element in the list, and no element passes the exam.

The reason for the error is that your code is not guaranteed to execute back at all if the list is empty, then you call return Leave at the conclusion of the function without The compiler is telling you this.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -