0

PFUser (「所有者」) へのポインターを含む PFObject を配布しようとしています。

ここに画像の説明を入力

これが私のフェッチコードです:

public func collectHashTags(#sender:UIViewController, withinGeoCoordinate geoPoint:PFGeoPoint) {
    var query = PFQuery(className:"Tag")
    query.includeKey("owner")  //...note: this doesn't give me the owner object.

    //    query.whereKey("lastGeo", nearGeoPoint:geoPoint, withinKilometers:2)

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {

        let tagArray = query.findObjects() as [PFObject]
        if tagArray.count > 0 {
            for x in 0...(tagArray.count - 1) {
                disseminateTags(tag:tagArray[x])   // ...load global Tag Array.
            }
        } else {
            showAlert(sender, withTitle:"No Data", withMessage:"The HashTag file is empty.")
        }

    });

}

以下は、取得したいデータを持つ PFObject である「タグ」です。

private func disseminateTags(#tag:PFObject) {

    let owner:PFUser = tag[gParseOwner] as PFUser

    let parseID = tag.objectId as String
    let displayName = tag[gParseDisplayName] as String
    let description = tag[gParseDescription] as String
    let radius = tag[gParseRadius] as CGFloat
    let tagPublicFlag = tag[gParsePublic] as Bool
    let startTime = tag[gParseStartTime] as NSDate
    let endTime = tag[gParseEndTime] as NSDate
    let media = tag[gParseMedia]? as [Int]

    let startTimeString:String = startTime.toString()
    let endTimeString:String = endTime.toString()

    // Create the local hashTag object:
    let myTag = hashTag(parseID: parseID, name: displayName, havingDescription: description, owner: owner)
    myTag.radius = radius
    myTag.publicFlag = tagPublicFlag
    myTag.startTimeStamp = startTimeString
    myTag.endTimeStamp = endTimeString

    gTagArray.append(myTag)

}

ご覧のとおり、「タグ」にはデータがあります。PFUser オブジェクトである「所有者」を広めたい:

(lldb) po tag
<Tag: 0x7fac1f91c950, objectId: 5J1dNXUdaM, localId: (null)> {
    Media =     (
        3,
        2,
        1
    );
    accessPemission = 1;
    description = "Hashbrown Potatoes";
    displayName = Smirf123;
    endTime = "2104-12-17 20:20:00 +0000";
    geoPoint = "<PFGeoPoint: 0x7fac1f99a990, latitude: 40.000000, longitude: -30.000000>";
    owner = "<PFUser: 0x7fac1f993370, objectId: hk7zYRK4xB>";
    public = 1;
    radius = 2000;
    startTime = "2104-12-15 20:20:00 +0000";
}

しかし、私は問題に直面しています。どうやら「所有者」を取得しました (オブジェクト ID に注意してください。上記を参照してください) が、デバッガーでそれを確認できません。 ここに画像の説明を入力


2 回目の試行:

'includeKey("owner") を使用しても役に立ちませんでした。だから私はそれをコメントアウトして、「所有者」属性が「タグ」クラスの兄弟に含まれるようにしました。

次に、所有者(id) フィールドでクエリを実行しようとしました(参照: https://www.parse.com/docs/ios_guide#queries/iOS ):

public func collectHashTags(#sender:UIViewController, withinGeoCoordinate geoPoint:PFGeoPoint) {
    var query = PFQuery(className:"Tag")
   // query.includeKey("owner")

    //    query.whereKey("lastGeo", nearGeoPoint:geoPoint, withinKilometers:2)

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {

        let tagArray = query.findObjects() as [PFObject]


        if tagArray.count > 0 {
            for x in 0...(tagArray.count - 1) {
                disseminateTags(tag:tagArray[x])   // ...load global Tag Array.
            }
        } else {
            showAlert(sender, withTitle:"No Data", withMessage:"The HashTag file is empty.")
        }

    });

}

private func disseminateTags(#tag:PFObject) {

    let owner = tag[gParseOwner] as PFUser

    owner.fetchIfNeededInBackgroundWithBlock {
        (object: PFObject!, error: NSError!) -> Void in

        if error != nil {
            println("Error: \(error)")
        } else {
            println("Fetched Owner: \(object)")
        }
    }
}

今回は、NSError に次のフラグが付けられました。

...Error: object not found for get (Code: 101, Version: 1.5.0)
...Error: object not found for get (Code: 101, Version: 1.5.0)
...Error: object not found for get (Code: 101, Version: 1.5.0)
...Error: object not found for get (Code: 101, Version: 1.5.0)
Error: Error Domain=Parse Code=101 "The operation couldn’t be completed. (Parse error 101.)" UserInfo=0x7ff9d260af40 {error=object not found for get, code=101}
Error: Error Domain=Parse Code=101 "The operation couldn’t be completed. (Parse error 101.)" UserInfo=0x7ff9d410ee80 {error=object not found for get, code=101}
Error: Error Domain=Parse Code=101 "The operation couldn’t be completed. (Parse error 101.)" UserInfo=0x7ff9d410ee20 {error=object not found for get, code=101}
Error: Error Domain=Parse Code=101 "The operation couldn’t be completed. (Parse error 101.)" UserInfo=0x7ff9d41082a0 {error=object not found for get, code=101}


3 回目の試行(後続の fetchIfNeeded() を使用):

public func collectHashTags(#sender:UIViewController, withinGeoCoordinate geoPoint:PFGeoPoint) {
    var query = PFQuery(className:"Tag")

    //    query.whereKey("lastGeo", nearGeoPoint:geoPoint, withinKilometers:2)

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {

        let tagArray = query.findObjects() as [PFObject]?

        if tagArray != nil {
            let myTag = tagArray![0]
            println("***myTag: \(myTag)")
            let myName = myTag["displayName"] as String
            println("displayName: \(myName)")

            let myOwner = myTag["owner"] as PFUser
            myOwner.fetchIfNeeded()

            println("**** myOwner: \(myOwner)")
        }


    });

}

出力:

***myTag: <Tag: 0x7fa5d87e8f70, objectId: 5J1dNXUdaM, localId: (null)> {
    Media =     (
        3,
        2,
        1
    );
    accessPemission = 1;
    description = "Hashbrown Potatoes";
    displayName = Smirf123;
    endTime = "2104-12-17 20:20:00 +0000";
    geoPoint = "<PFGeoPoint: 0x7fa5de104770, latitude: 40.000000, longitude: -30.000000>";
    owner = "<PFUser: 0x7fa5de108070, objectId: hk7zYRK4xB>";
    public = 1;
    radius = 2000;
    startTime = "2104-12-15 20:20:00 +0000";
}
displayName: Smirf123
2014-12-14 15:09:12.004 Bliss2[4757:181319] Error: object not found for get (Code: 101, Version: 1.5.0)
**** myOwner: <PFUser: 0x7fa5de108070, objectId: hk7zYRK4xB, localId: (null)> {
}

私はここで迷っています。
ホスティング レコードを使用して PFUser ポインターを配布することは、それほど難しくありません。
「所有者」(PFUser) から (文字列と画像) 属性を取得/抽出するにはどうすればよいですか?

4

1 に答える 1