swift Parse server についてまとめてみる

import Parse

podは省略しますね。

newのときは PFObject(className: "Xxxx")

saveInBackground を使うと保存できているかどうかの確認が可能

updateのとき

PFQuery(className: "Xxxx")でgetして

getObjectInBackground メソッドでupdat クロージャー利用

import UIKit
import Parse

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tweet = PFObject(className: "Tweet")
        tweet["text"] = "Good morning!"
        tweet.saveInBackground { (scceeded, error) in
            if (scceeded){
                print(tweet)
            }else{
                print("error")
            }

        }
    
        let query = PFQuery(className: "Tweet")
        query.getObjectInBackground(withId: "AIhZtJ6zhX") { (object, error) in
            if let comment = object{
                comment["text"] = "Good night!"
                comment.saveInBackground { (succeeded, error) in
                    if (succeeded){
                        print("good night")
                    }else{
                        print("error")
                    }
                }
            }else{
                print("error")
            }
        }
        
    }