解析:更改指针的值 [英] Parse: change a pointer's value
问题描述
例如,我有两个类Player
和Game
,而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
来更改player
的name
怎么办?喜欢:
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
?
推荐答案
-
是的,当您保存包含指向其他对象的指针的对象时,递归保存是正确的.所有指向的对象将被保存.由于
game
指向player
,因此在保存game
时也会保存player
.
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 toplayer
,player
will also be saved whengame
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屋!