【问题标题】:Swift - Parse Query whereKey containsSwift - 解析查询 whereKey 包含
【发布时间】:2017-03-03 21:54:18
【问题描述】:

我有一个已保存到 LDS 的解析对象,我想通过 1 个键和另一个键下的条目来搜索它。

Key:这很好。

checkQuery.whereKeyExists("File-rZVgZNpNuB")

包含以下内容的密钥:这不起作用。

checkQuery.whereKey("seachKey", contains: "myItem0000000000")

控制台正在打印:

 -[__NSArrayM length]: unrecognized selector sent to instance 0x7c09bbb0

我猜是因为 mySearchString 是“searchKey”字段中的一个对象,它返回一个 NSMutable 数组。一旦我有了对象,它就很容易从数组中取出数据,但我需要在“searchKey”字段中搜索这个字符串来找到对象。由于各种原因,我不能只用“myItem0000000000”键保存对象。也许我可以在保存对象时将其添加为第三个键,但这似乎有点混乱。

它就在那里,如果我通过 SQL Lite 查看对象,我可以看到它。

{"className":"downloadedAudio","__complete":true,"__operations":[{"ACL":{"*":{"read":true},"rZVgZNpNuB":{"write":true,"read":true}},"File-rZVgZNpNuB":{"__op":"Add","objects":[{"url":"https:\/\/parse-server-nextbreath-s3-bucket.s3.amazonaws.com\/b5d2110dce0b50dc3a1c620731fad66e_The%20Name%20of%20the%20Wind%2024-92.mp3","name":"b5d2110dce0b50dc3a1c620731fad66e_The Name of the Wind 24-92.mp3","__type":"File"}]},"__uuid":"77AE38AF-1ADB-4795-9BB0-5A5AB7205E28","__updatedAt":{"iso":"2017-03-03T21:28:19.637Z","__type":"Date"},"searchKey":{"__op":"Add","objects":["myItem0000000000"]}}],"isDeletingEventually":0}

---- 编辑 ---- 搜索:

        let searchKey = "File-\(PFUser.current()!.objectId!)"
        let checkQuery = PFQuery(className: "downloadedAudio")
        checkQuery.whereKeyExists(searchKey)
        //checkQuery.whereKeyExists(item.name)
        //checkQuery.whereKey("seachKey", contains: item.name)
        checkQuery.fromLocalDatastore()
        checkQuery.getFirstObjectInBackground(block: { (object, error) in
            if object != nil {
                // object?.unpinInBackground()
                object?.unpinInBackground(block: { (success, error) in
                    if success {

保存:

let query = PFQuery(className: "Part")
query.whereKey("objectId", equalTo: selectedObjectId)
query.getFirstObjectInBackground { (object, error) in
    if error != nil || object == nil {
       // ---- 
    } else {

        let searchKey = "File-\(PFUser.current()!.objectId!)"
        downloadedAudio.add(object?.object(forKey: "partAudio") as! PFFile, forKey: file)
        downloadedAudio.add(object?.object(forKey: "partName") as! String, forKey: searchKey)
        let downloadedFile = object?.object(forKey: "partAudio") as! PFFile
        downloadedFile.getDataInBackground({ (data, error) in

【问题讨论】:

  • searchKey 字段是否是解析服务器中的类型数组?你的最后一行有一些额外的东西......分享你的整个快速解析下载代码以及它打印什么错误......在我的项目中它工作得很好......

标签: swift parse-platform


【解决方案1】:

我相信您会收到该错误,因为 "File-rZVgZNpNuB" 是无效密钥。请记住,键只能以小写字母开头。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多