objective-c - 如何在 Swift 中使用带有关键字名称的 Objective-C 类

标签 objective-c swift naming

我们正尝试在我们的 Swift 项目中使用 BZObjectStore 库 ( https://github.com/expensivegasprices/BZObjectStore )。

但是在这个库中,他们使用'where'作为名称来设置查询条件。

BZObjectStoreConditionModel *fetchCondition = [BZObjectStoreConditionModel condition];
fetchCondition.sqlite.where = @"name = 'sample1' and price > 50";
fetchCondition.sqlite.orderBy = @"name desc";

NSArray *objects = [os fetchObjects:[SampleModel class] condition:fetchCondition error:&error];

但不幸的是,'where' 是 Swift 中的关键字。我们不想手动更改 BZObjectStore 中的代码。那么有什么办法可以解决这个问题吗?

最佳答案

你必须使用反引号:

fetchCondition.sqlite.`where` = @"name = 'sample1' and price > 50";

To use a reserved word as an identifier, put a backtick (`) before and after it. For example, class is not a valid identifier, but `class` is valid. The backticks are not considered part of the identifier; `x` and x have the same meaning.

The Swift Programming Language – Lexical Structure

关于objective-c - 如何在 Swift 中使用带有关键字名称的 Objective-C 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31717511/

相关文章:

ios - 将原点移回原始位置

ios - 以编程方式根据文本长度自定义 UILabel 宽度

ios - Swift 中的分割操作

objective-c - 如何将 NSTableView 绑定(bind)到多个核心数据实体类型

屏幕边缘附近的 iOS UIButton 无法正常响应点击

ios - [NSConcreteTextStorage属性:atIndex:effectiveRange:]: Range or index out of bounds error in NSMutableAttributedString

ios - 自定义 NSExpression 函数,例如 sin(x)

variables - 哪个变量名合适?

C++ MFC 命名线程以便 Procmon 可以看到它们

variables - 是否有变量命名约定的简明目录?