下記ページを参考に、NiftyCloud mBaaS を試しています。
次のコードで、エラーも出ませんが、データストアへの読み書きができないので、ご教示いただけますでしょうか。
NiftyCloud mBaaS + Swift データストアへの読み書き
swift
1import UIKit 2import NCMB 3 4 5@UIApplicationMain 6class AppDelegate: UIResponder, UIApplicationDelegate { 7 8 var window: UIWindow? 9 struct companyInfo{ 10 var companyID:String 11 var companyName:String 12 } 13 14 15 16 17 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 // APIキーの設定とSDK初期化 19 NCMB.setApplicationKey("....", clientKey: ".....") 20 21 return true 22 } 23 24 // クラスのNCMBObjectを作成 追加分/* 25 let object = NCMBObject(className: "company") 26 object?.setObject("nanikadekitaka3!", forKey: "message") 27 object?.saveInBackground { (error: Error?) in 28 if error != nil { 29 // 保存に失敗した場合の処理 30 print( "失敗" ) 31 } else { 32 // 保存に成功した場合の処理 33 print( "成功" ) 34 } 35 } 36 return true 37 } 38 //追加分*/ 39 func getCompanyName(_ companyID:String) -> String { 40 var companyName:String = "" 41 42 let query = NCMBQuery(className: "Company") 43 query?.whereKey("companyID", equalTo: companyID) 44 var results:[AnyObject] = [] 45 do { 46 results = try query!.findObjects() as [AnyObject] 47 } catch let error1 as NSError { 48 print("\(error1)") 49 return companyName 50 } 51 if results.count > 0 { 52 let result = results[0] as? NCMBObject 53 companyName = result?.object(forKey:"companyName") as? String ?? "nanikahairetu" 54 } 55 return companyName 56 57 } 58 59 60 func addCompany(_ company:companyInfo) { 61 62 let companyObject = NCMBObject(className: "Company") 63 64 companyObject?.setObject(company.companyName,forKey:"CompanyName") 65 companyObject?.setObject(company.companyID,forKey:"companyID") 66 67 companyObject?.saveInBackground({(error) in 68 if error != nil {print("Save error : ",error!)} 69 }) 70 71 } 72 73 func updateCompany(_ company:companyInfo) { 74 75 let query = NCMBQuery(className: "Company") 76 query?.whereKey("companyID", equalTo: company.companyID) 77 var results:[AnyObject] = [] 78 do { 79 results = try query!.findObjects() as [AnyObject] 80 } catch let error1 as NSError { 81 print("\(error1)") 82 return 83 } 84 if results.count > 0 { 85 let obj = results[0] as! NCMBObject 86 87 obj.setObject(company.companyName,forKey:"CompanyName") 88 89 obj.saveInBackground({(error) in 90 if error != nil {print("Save error : ",error!)} 91 }) 92 93 } 94 } 95 96 97 98 func applicationWillResignActive(_ application: UIApplication) { 99 // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 100 // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 101 } 102 103 func applicationDidEnterBackground(_ application: UIApplication) { 104 // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 105 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 106 } 107 108 func applicationWillEnterForeground(_ application: UIApplication) { 109 // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 110 } 111 112 func applicationDidBecomeActive(_ application: UIApplication) { 113 // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 114 } 115 116 func applicationWillTerminate(_ application: UIApplication) { 117 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 118 } 119 120 121} 122
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/13 07:07
2017/01/13 07:38
2017/01/13 08:04 編集
2017/01/13 08:12
2017/01/13 09:07 編集
2017/01/13 09:23
2017/01/13 09:45
2017/01/13 10:01
2017/01/13 10:14