Home>

I want to get the objectId automatically assigned on the server side at the time of saving in NCMB of Nifty Cloud. How should I describe it? I would appreciate it if you could teach me.

Corresponding source code
var object: NCMBObject = NCMBObject (className: "TestClass")
// Set the information to be saved here (omitted)
object.saveInBackground (callback: {result in
    DispatchQueue.global (qos: .default) .async {
      // Run in subthread (background)
        DispatchQueue.main.async {
            switch result {
                case .success:
                    // Processing when saving is successful
                    print ("Saved successfully")
                    // ① Here, I want to get the ID set at the time of saving
                    // ↓ Syntax error
                    guard let objectId: Stirng = object.objectId else {return}
                    // ② ↓ Also, the same error occurred in this writing method.
                    guard let objectId: Stirng = result.objectId else {return}
                case let .failure (error):
                    // What to do if saving fails
                    print ("Failed to save: \ (error)")
            }
        }
    }
})
Cannot find type'Stirng' in scope
What I tried

I think I could have done it this way before, but I didn't know how to write it now.

let object = NCMBObject (className: "TestClass")
// DB save
object! .save (nil)
// Get ID
let myObjectId = object! .objectId
  • Answer # 1

    Cannot find type'Stirng' in scope

    So I think it's just a typo (StirngNotString).

      guard let objectId: Stirng = object.objectId else {return}

    Not

      guard let objectId: String = object.objectId else {return}

    By the way,objectIdIsStringI know it's a type, so I don't think it's necessary to write the type explicitly.


    Also handed over to the closureresult resultThe type isNCMBResultBecause it is a typeStringPlease note that you cannot cast to.