Swift/Cloudkit 谓词格式

标签 swift nspredicate cloudkit

我正在尝试使用 CloudKit 数据库中存储的坐标编写谓词。我正在努力寻找有关格式化它的任何准确文档。这是我的想法:

NSPredicate(format: "distanceToLocation:fromLocation: (%K,%@) < 1000", "locationcoordinates")

我收到以下错误:

由于未捕获的异常“CKException”而终止应用程序,原因:“distanceToLocation:fromLocation 的预期 CLLocation 参数:”

谁能帮我纠正这个谓词吗?我不确定我需要添加什么参数。

最佳答案

在您的谓词中,您有 2 个参数。 %K 和 %@ 但仅提供 1 个值。

应该是这样的

    var location:CLLocation = CLLocation(latitude: 0, longitude: 0)
    var radiusInKilometers:CGFloat = 1000;
    var predicate: NSPredicate = NSPredicate(format: "distanceToLocation:fromLocation:(location, %@) < %f", location, radiusInKilometers)!

关于Swift/Cloudkit 谓词格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28675907/

相关文章:

swift - 以替代格式追加字符

swift - 如何快速将完成按钮向右移动

core-data - 获取 entity.attribute == @"somevalue"的请求

ios - 如何仅比较文本中选定的字符串与 objective-c 中的给定输入

ios - 使用 NSPredicate 过滤对象和键(需要拆分)

ios - 自动增加/减少 UITableViewCell 中的 UILabelView 高度?

swift - 无法分配给值 : 'message' is a 'let' constant in a fucntion

ios - 禁用 CloudKit 调试日志

ios - CloudKit 如何与多个设备同步?

iOS App 不会使用自定义 iCloud 容器