Arrays 在解析中替换对象
我正在尝试删除Parse中保存的对象并替换它。我的代码不起作用。我的解析数据库只添加具有相同数组名称的对象。这是我的密码Arrays 在解析中替换对象,arrays,swift,parse-platform,pfobject,Arrays,Swift,Parse Platform,Pfobject,我正在尝试删除Parse中保存的对象并替换它。我的代码不起作用。我的解析数据库只添加具有相同数组名称的对象。这是我的密码 @IBAction func finalSaveBTN(sender: AnyObject) { videoARY = [videoId, vidTitleText, vidDescription, vidIMG] let videoSave = PFObject(className: "UserVideos") vi
@IBAction func finalSaveBTN(sender: AnyObject)
{
videoARY = [videoId, vidTitleText, vidDescription, vidIMG]
let videoSave = PFObject(className: "UserVideos")
videoSave.deleteInBackgroundWithBlock { (success, error) -> Void in
if success == true
{
videoSave["userObjectId"] = PFUser.currentUser()!.objectId
videoSave["vid\(self.saveValueLBL.text!)"] = self.videoARY
videoSave.saveInBackgroundWithBlock { (success, error ) -> Void in
if success == true
{
print("Succesfull")
}
}
}
else
{
print("Error")
}
}
}
我想删除该对象,但如果有人知道如何成功更新解析数组,这也会有所帮助。多谢各位
***更新****
我正在尝试这个,也不起作用,可能有什么问题
@IBAction func finalSaveBTN(sender: AnyObject)
{
videoARY = [videoId, vidTitleText, vidDescription, vidIMG]
let videoSave = PFObject(className: "UserVideos")
let query = PFQuery(className: "UserVideos")
query.whereKey("userObjectId", equalTo: PFUser.currentUser()!.objectId!)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
for object in objects!
{
let vid = object["vid\(self.saveValueLBL.text!)"]!
vid!.delete()
}
}
videoSave["userObjectId"] = PFUser.currentUser()!.objectId
videoSave["vid\(self.saveValueLBL.text!)"] = self.videoARY
videoSave.saveInBackgroundWithBlock { (success, error ) -> Void in
if success == true
{
print("Succesful")
}
}
}
****更新*****
我正在删除videoSave的所有视频。如果您对如何瞄准特定阵列有任何建议,我将不胜感激。我将尝试返工并保存为一个简单的文件
@IBAction func finalSaveBTN(sender: AnyObject)
{
videoARY = [videoId, vidTitleText, vidDescription, vidIMG]
let videoSave = PFObject(className: "UserVideos")
let query = PFQuery(className: "UserVideos")
query.whereKey("userObjectId", equalTo: PFUser.currentUser()!.objectId!)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
for object in objects!
{
if let vid = object["vid\(self.saveValueLBL.text!)"]!
{
vid.deleteInBackground()
vid.saveInBackground()
}
}
}
videoSave["userObjectId"] = PFUser.currentUser()!.objectId
videoSave["vid\(self.saveValueLBL.text!)"] = self.videoARY
videoSave.saveInBackgroundWithBlock { (success, error ) -> Void in
if success == true
{
print("Succesful")
}
}
这里有一些障碍,让我带你穿过 1: 第一个问题是,您试图删除正在创建的全新对象,该对象尚未保存到服务器。这就是
让…=PFObject(类名:…)
则创建一个新对象
2:更新解析数组真的很容易!如果您的代码中有对象,只需使用诸如或之类的函数更改对象,然后使用.saveinbackgroundithblock
,瞧!如果您没有该对象,则需要首先创建一个没有来自服务器的数据的对象版本,然后让它从解析服务器获取其信息,然后您可以修改并保存它。这是你做这两件事的方法
PFObject(withoutDataWithObjectId: objectId)
PFObject().fetchIfNeededInBackgroundWithBlock({})
最后,如果您没有对象的objectId,那么您必须使用PFQuery
,然后使用那里的。whereKey(…)
进行筛选,直到找到为止
3:您是否知道,通过调用videoSave[“vid\(self.saveValueLBL.text!)”]=self.videoARY
,您正在将self.saveValueLBL.text的字符串保存到解析服务器中名为vid
+的列中代码>?您可能正在动态创建解析列。只是抬头一看
4:另一个问题是videoSave[“vid\(self.saveValueLBL.text!)”]=self.videoARY
行。无法保存pffile的数组。您必须将该信息保存在一个单独的列中,指定类型为PFFile
5:在您的新代码块中,我认为delete()
的工作方式与您认为的不同。如果要删除整个对象,请使用object.deleteInBackground()
,如果只想删除该对象的属性,可以使用object.removeObjectForKey(…)
,然后使用object.saveInBackground()
这一切都有意义吗?我不必将我的数组转换为PFFile。我只需要添加第二个查询。基本上我是在查询当前用户的所有视频。添加query.whereKeyExists将其缩小到特定的vid。它还将使检索查询更容易。这是
@IBAction func finalSaveBTN(sender: AnyObject)
{
videoARY = [videoId, vidTitleText, vidDescription, vidIMG]
let query = PFQuery(className: "UserVideos")
query.whereKey("userObjectId", equalTo: PFUser.currentUser()!.objectId!)
query.whereKeyExists("vid\(self.saveValueLBL.text!)")
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
for object in objects!
{
object.deleteInBackground()
object.saveInBackground()
}
}
let videoSave = PFObject(className: "UserVideos")
videoSave.setObject(self.videoARY, forKey: "vid\(self.saveValueLBL.text!)")
videoSave["userObjectId"] = PFUser.currentUser()!.objectId
videoSave.saveInBackgroundWithBlock { (success, error ) -> Void in
if success == true
{
print("Succesful")
}
}
}
麦克莱恩回答#3…是的,我知道我在创作“vid1”。saveValueLBL.text提供来自步进器的整数。目标是让用户保存一组视频信息,并在找到新的#1、2或3时进行替换。最多10个。我将尝试更新到列。我不知道objectId,因为它们会随着每次新的保存而改变。我以前做过object.removeObjectForKey。没用。我想我有一个问题,没有人能给出足够的答案。我试图让用户保存一个特定的数组,并在找到新的1-10号视频时替换它。将其存储为PFFile和try-and-delete会更容易吗。顺便说一句,我成功地收回了信息。我只想让它停止显示几个#1,只显示最近的。好的,我可以拥有它。请参阅更新。我很抱歉,我可以删除对象,但它会删除所有视频。我一直在尝试获取对象[vid1],但出现了以下错误……“[\uu nsarray deleteInBackground]:未识别的选择器发送到实例0x7facd8f84390”。我将尝试另存为PFFile。如果你知道什么,请告诉我。
@IBAction func finalSaveBTN(sender: AnyObject)
{
videoARY = [videoId, vidTitleText, vidDescription, vidIMG]
let query = PFQuery(className: "UserVideos")
query.whereKey("userObjectId", equalTo: PFUser.currentUser()!.objectId!)
query.whereKeyExists("vid\(self.saveValueLBL.text!)")
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
for object in objects!
{
object.deleteInBackground()
object.saveInBackground()
}
}
let videoSave = PFObject(className: "UserVideos")
videoSave.setObject(self.videoARY, forKey: "vid\(self.saveValueLBL.text!)")
videoSave["userObjectId"] = PFUser.currentUser()!.objectId
videoSave.saveInBackgroundWithBlock { (success, error ) -> Void in
if success == true
{
print("Succesful")
}
}
}