xcode8 iOS函数返回值使用警告

Posted Rinpe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xcode8 iOS函数返回值使用警告相关的知识,希望对你有一定的参考价值。

没有使用返回值时, 警告

swift:

@warn_unused_result func doSomething() -> Bool {
  return true
}

OC:

- (BOOL)doSomething __attribute__((warn_unused_result)) {
  return YES;
}

 

没有使用返回值时, 不警告

swift:

@discardableResult func doSomething() -> Bool {
  return true
}

OC:

To prevent the compiler from flooding us with warnings when importing Objective-C code the @discardableResult attribute is automatically added for all non-void functions that are not marked with the ((warn_unused_result)) attribute.

以上是关于xcode8 iOS函数返回值使用警告的主要内容,如果未能解决你的问题,请参考以下文章