提问人:philip.a20 提问时间:2/13/2022 更新时间:2/13/2022 访问量:542
在范围内找不到类型“ParseCloud” - Back4App ios 实现
Cannot find type 'ParseCloud' in scope - Back4App ios implementation
问:
我正在使用 Swift、Xcode 和 back4app(Parse) 开发一个 ios 应用程序。我正在尝试编写一个应用程序启动的函数,该函数连接到后端的函数,但收到此错误。任何帮助都会很棒!先谢谢你。
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)")
}
}
错误:在作用域中找不到类型“ParseCloud”
答:
1赞
CoreyB
2/13/2022
#1
如果不在范围内,则似乎您没有在文件顶部添加。请确保正确安装了 SDK。首选方法是 Swift Package Manager,但 cocoapods 和 carthage 也应该可以工作。ParseCloud
import ParseSwift
请务必查看 Playground 文件,了解如何使用 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)")
}
评论
0赞
philip.a20
2/15/2022
非常感谢!!!我导入了“Parse”,但没有导入“ParseSwift”
评论