简体   繁体   English

使用swift从解析中保存和检索数据

[英]Saving and retrieving data from parse using swift

I was successfully able to save data (integer) to parse using swift. 我成功地保存了数据(整数)以使用swift进行解析。

var gameScore = PFObject(className:"GameScore")
gameScore["score"] = highscore

I have successfully stored in data in an objectId named "EN34LdmbSB" I found this objectId by logging into parse.com and looking it up. 我已经成功存储在名为“ EN34LdmbSB”的objectId中的数据中,通过登录parse.com并进行查找找到了该objectId。 I have later unsuccessfully tried to use same objectId to retrieve data and it did not work. 后来我尝试使用相同的objectId检索数据失败,但没有成功。 I have to 2 questions: 1) How to I retrieve this data from parse. 我有2个问题:1)如何从解析中检索此数据。 2) If this app is downloaded, say for example by 1000 users, then 1000 unique objectIds will be created when users save their score. 2)如果下载了此应用,例如由1000个用户下载,则当用户保存其得分时,将创建1000个唯一的objectId。 How do I then look up their score using their unique objectIds? 然后,如何使用其唯一的objectIds查找他们的分数?

I am new to database and Parse so please pardon my naivety. 我是数据库和解析的新手,请原谅我的天真。 I am currently using NSUserDefaults to store my game score. 我目前正在使用NSUserDefaults来存储我的游戏分数。 I am trying to get a more secure way of storing the score data, hence using parse. 我试图获得一种更安全的方式来存储乐谱数据,因此使用解析。 Tried using KeyChain but did not get very far. 尝试使用KeyChain,但距离还很远。 Thank you 谢谢

You can easily retrieve the data using one of their method in iOS SDK: 您可以使用iOS SDK中的一种方法轻松检索数据:

PFQuery *query = [PFQuery queryWithClassName:@"GameScore"];
[query whereKey:@"playerName" equalTo: highscore];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
  if (!error) {
    // The find succeeded.
    NSLog(@"Successfully retrieved %d scores.", objects.count);
    // Do something with the found objects
    for (PFObject *object in objects) {
        NSLog(@"%@", object.objectId);
    }
  } else {
    // Log details of the failure
    NSLog(@"Error: %@ %@", error, [error userInfo]);
  }
}];

You can look it up in the tutorial they provided and it's really helpful and saving time: https://parse.com/docs/ios_guide#queries/iOS 您可以在他们提供的教程中查找它,它确实对您有所帮助,而且可以节省时间: https : //parse.com/docs/ios_guide#queries/iOS

For you second question, I don't quite get what you want to ask. 对于您的第二个问题,我不太了解您想问的问题。 Parse built the backend for you so that you don't have to create database to manage your data. Parse为您构建了后端,因此您不必创建数据库来管理数据。 I suggested you to go check what Parse truly does or you can modify it so that I can understand better. 我建议您检查一下Parse的真正作用,或者可以对其进行修改,以便更好地理解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM