6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NiftyCloud(MBaaS)のiOSクイックスタート Swift 2 ver.

Last updated at Posted at 2016-04-24

#はじめに
Parseが1年後に使えなくなるということでざわざわしてましたが・・MBaaSのNiftyCloud使ってみようと思いNiftyCloudのイントロダクションに手を出してみました。
iOSのクイックスタートはObj-Cなので、こちらのNiftyCloud(MBaaS)のiOSクイックスタートをObjective-CからSwiftに書き換えてみたを参考に進めていました。Swiftのバージョンアップにより若干の変更点があったのでここに忘備録として。

#swift 2 ver
これをAppDelegate.swiftのdidFinishLaunchingWithOptionsに入れてあげます。

AppDelegate.swift
 
        NCMB.setApplicationKey("<YOUR_APPLICATION_KEY>", clientKey: "<YOUR_CLIENT_KEY>")
        
        let query: NCMBQuery = NCMBQuery(className: "TestClass")
        query.whereKey("message", equalTo: "test")
        query.findObjectsInBackgroundWithBlock({(object, error) in
            if (error == nil) {
                if (object.count > 0) {
                    let message = object[0].objectForKey("message") as! NSString!
                    print("[FIND]\(message)")
                } else {
                    var saveError: NSError?
                    let obj = NCMBObject(className: "TestClass")
                    obj.setObject("test", forKey: "message")
                    obj.save(&saveError)
                    if (saveError == nil){
                        print("[SAVE]done")
                    } else {
                        print("[SAVE ERROR]\(saveError)")
                    }
                }
            
            } else {
                print(error.localizedDescription)
            }
        })

これで多分動くと思います。

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?