Xcode 11 是否开始忽略缺少的“return"语句错误? [英] did Xcode 11 start ignoring missing 'return' statement errors?

查看:40
本文介绍了Xcode 11 是否开始忽略缺少的“return"语句错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个同事无法编译该项目(我认为他使用的是旧版本的 Xcode,我使用的是 11.2.1).但出于某种原因,下面的代码一直在为我工作和编译?我认为我应该因为缺少 return 语句而出现语法错误?

 覆盖 func serviceType() ->服务类型 {.根据}覆盖 func operationType() ->NQO类型{.邮政}覆盖 func doSupportOffline() ->布尔{错误的}

解决方案

看这里:https://docs.swift.org/swift-book/LanguageGuide/Functions.html

<块引用>

具有隐式返回的函数:如果函数的整个主体是单个表达式,该函数隐式返回表达.例如,下面的两个函数具有相同的行为:

func greeting(for person: String) ->细绳 {你好,"+人+!"}

<块引用>

greeting(for:) 函数的整个定义就是greeting它返回的消息,这意味着它可以使用这种更短的形式.

A coworker of mine can't compile the project (I think he's on an older version of Xcode, I'm on 11.2.1). But for some reason the code below has been working and compiling for me? I would think I should be getting syntax errors because of missing return statements?

    override func serviceType() -> ServiceType {
        .base
    }

    override func operationType() -> NQOType {
        .Post
    }

    override func doesSupportOffline() -> Bool {
        false
    }

解决方案

Look at here: https://docs.swift.org/swift-book/LanguageGuide/Functions.html

Functions With an Implicit Return: If the entire body of the function is a single expression, the function implicitly returns that expression. For example, both functions below have the same behavior:

func greeting(for person: String) -> String {
    "Hello, " + person + "!"
}

The entire definition of the greeting(for:) function is the greeting message that it returns, which means it can use this shorter form.

这篇关于Xcode 11 是否开始忽略缺少的“return"语句错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆