OGeek|极客世界-中国程序员成长平台

标题: ios - 解析查询,其中键包含 A 或 B - Swift [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:12
标题: ios - 解析查询,其中键包含 A 或 B - Swift

我正在尝试运行一个解析查询,其中某个字段包含今天的日期或明天的日期。这是我到目前为止的代码:

var date = Date() // first date
    let calendar = Calendar.current
    let date2 = (calendar as NSCalendar).date(byAdding: .day, value: 7, to: date, options: [])!
    let dateFormatterateFormatter = DateFormatter()
    dateFormatter.dateFormat = "yyyy-MM-dd"
    let todaysString:String = dateFormatter.string(from: date)
    let tomorrowString:String = dateFormatter.string(from: date2)

    let query = PFQuery(className: "Events")
    query.whereKey("dateString", contains: todaysString || tomorrowString)

但这不会运行,因为它无法转换值。有谁知道我应该如何编写这一行来表明 dateString 需要包含 todaysString 或 tomorrowString?提前致谢。



Best Answer-推荐答案


您需要创建单独的查询,并将它们与 PFQuery.orQueryWithSubqueries(todayQuery, tomorrowQuery) 连接起来。

关于ios - 解析查询,其中键包含 A 或 B - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40895139/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4