Home > Enterprise >  Cannot find type 'ParseCloud' in scope - Back4App ios implementation
Cannot find type 'ParseCloud' in scope - Back4App ios implementation

Time:02-15

I am developing an ios app using Swift, Xcode, and back4app(Parse). I am trying to write an application launched function that connects to a function on the back end but am receiving this error. Any help would be great! Thank you in advance.

struct CloudUser: ParseCloud {
      typealias ReturnType = String
      var functionJobName: String
      var username: String
      var password: String
      var email: String
    }
    
    let cloudUser = CloudUser(functionJobName: "userRecord", username: self.userName.text!, password: self.password.text!, email: self.email.text!)
    cloudUser.runFunction { result in
          switch result {
          case .success(let response):
            print("Response from cloud function sumNumbers: \(response)")
          case .failure(let error):
            assertionFailure("Error calling cloud function sumNumbers: \(error)")
          }
        }

Error: Cannot find type 'ParseCloud' in scope

CodePudding user response:

If ParseCloud isn't in scope, it seems you didn't add import ParseSwift at the top of your file. Make sure you installed the SDK properly. The preferred way is Swift Package Manager, but cocoapods and carthage should work as well.

Be sure to look at the Playground files for examples on how to use the Swift SDK:

import ParseSwift

//: Create your own value typed `ParseCloud` type.
struct Hello: ParseCloud {

    //: Return type of your Cloud Function
    typealias ReturnType = String

    //: These are required by `ParseCloud`, you can set the default value to make it easier
    //: to use.
    var functionJobName: String = "hello"
}

//: Create another `ParseCloud` type.
struct TestCloudCode: ParseCloud {

    //: Return type of your Cloud Function
    typealias ReturnType = [String: Int]

    //: These are required by `ParseCloud`, you can set the default value to make it easier
    //: to use.
    var functionJobName: String = "testCloudCode"

    //: If your cloud function takes arguments, they can be passed by creating properties:
    var argument1: [String: Int]
}

//: Create another `ParseCloud` type.
struct TestCloudCodeError: ParseCloud {

    //: Return type of your Cloud Function
    typealias ReturnType = String

    //: These are required by `ParseCloud`, you can set the default value to make it easier
    //: to use.
    var functionJobName: String = "testCloudCodeError"
}

/*: Assuming you have the Cloud Function named "hello" on your parse-server:
     // main.js
     Parse.Cloud.define('hello', async (request) => {
       console.log('From client: '   JSON.stringify(request));
       return 'Hello world!';
     });
 */
let hello = Hello()

// Using async/await, the Playgounds shows how to use a completion handler
do {
  let result = try await hello.runFunction() 
  print("Response from cloud function: \(response)")

} catch {

  print("Error calling cloud function: \(error)")
}
  • Related