Swift function compiler error 'missing return'

后端 未结 3 1831
余生分开走
余生分开走 2021-01-23 04:58

I\'ve been trying to get this function to return a Bool value but I don\'t understand why i\'m getting the error \"missing return in a function expected to return \'Bool\'. I\'v

3条回答
  •  遥遥无期
    2021-01-23 05:32

    I suspect the compiler requires a return value for the case when the loop is not executed at all.

    Now, a ClosedRange can never be empty, so b[0]...b.endIndex won't ever be empty (if it results in an empty or invalid range, the code would crash), but the compiler is not smart enough to know that.

    PS: Are you sure b[0]...b.endIndex is actually the sequence you want to loop over. This creates a range from the first element of b to the endIndex of b. That doesn't make any sense to me.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题