解析:更改指针的值 [英] Parse: change a pointer's value

查看:75
本文介绍了解析:更改指针的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有两个类PlayerGame,而Game有一个字段player,它是指向Player的指针.正如Parse文档所说,save是递归的,因此我假设我可以通过仅保存game来保存player,就像:

For example, I have two class Player and Game, and Game has a field player which is a pointer to Player. As Parse documentation says, save is recursive, so I assume that I can save a player by only saving a game, just like:

let player = PFObject(className: "Player")
player["name"] = ABC
let game = PFObject(className: "Game")
game["player"] = player
game["round"] = 1
game.saveInBackground()

这是真的吗?

好吧,现在假设这是正确的,那么仅保存game来更改playername怎么办?喜欢:

Ok, now assuming that is true, then what about changing the player's name by only saving game? Like:

let player = game["player"] as! PFObject
player["name"] = BCD
game["round"] = 2
game.saveInBackground()

您能回答这两个问题吗?谢谢.

Could you please answer these two questions? Thank you.

另一个问题:如果要获取player["name"],在查询game时是否需要使用includeKey("player")?

Another question: If I want to get the player["name"], do I need to use includeKey("player") when querying the game?

推荐答案

  1. 是的,当您保存包含指向其他对象的指针的对象时,递归保存是正确的.所有指向的对象将被保存.由于game指向player,因此在保存game时也会保存player.

  1. Yes, it's true about the recursive saving when you save an object that includes pointers to other objects. All of the pointed-to objects will be saved. Since game points to player, player will also be saved when game is saved.

相关对象的更改(例如玩家名称)也应基于(1)保存.

The changes in a related object, such as the player's name, should also be saved based on (1).

由于查询不会以相应的递归方式自动检索相关的对象,因此在检索游戏时需要使用includeKey来检索相关的Player对象是正确的.

Since queries do not automatically retrieve related objects in a corresponding recursive manner, you are correct about needing to use includeKey to retrieve the related Player object when retrieving a Game.

这篇关于解析:更改指针的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆