没有使用返回值时, 警告

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.

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-25
  • 2021-10-27
  • 2021-12-06
  • 2021-12-07
猜你喜欢
  • 2022-12-23
  • 2021-08-11
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案