We are trying to use the BZObjectStore library (https://github.com/expensivegasprices/BZObjectStore) in our Swift project.
But in this library, they use 'where' as a name to set the query conditions.
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];
But unfortunately, 'where' is a keyword in Swift. We do not want to change the code in BZObjectStore manually. So is there any way we can resolve this ?
You have to use backticks:
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.
来源:https://stackoverflow.com/questions/31717511/how-to-use-objective-c-classes-with-names-which-are-keywords-in-swift