菜鸟教程小白 发表于 2022-12-11 18:12:01

ios - 解析查询,其中键包含 A 或 B - Swift


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

<pre><code>var date = Date() // first date
    let calendar = Calendar.current
    let date2 = (calendar as NSCalendar).date(byAdding: .day, value: 7, to: date, options: [])!
    let dateFormatter:DateFormatter = DateFormatter()
    dateFormatter.dateFormat = &#34;yyyy-MM-dd&#34;
    let todaysString:String = dateFormatter.string(from: date)
    let tomorrowString:String = dateFormatter.string(from: date2)

    let query = PFQuery(className: &#34;Events&#34;)
    query.whereKey(&#34;dateString&#34;, contains: todaysString || tomorrowString)
</code></pre>

<p>但这不会运行,因为它无法转换值。有谁知道我应该如何编写这一行来表明 dateString 需要包含 todaysString 或 tomorrowString?提前致谢。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您需要创建单独的查询,并将它们与 <code>PFQuery.orQueryWithSubqueries(todayQuery, tomorrowQuery)</code> 连接起来。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 解析查询,其中键包含 A 或 B - Swift,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/40895139/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/40895139/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 解析查询,其中键包含 A 或 B - Swift