gpt4 book ai didi

ios - '.' 之后的 Swift/iOS/预期成员名称

转载 作者:搜寻专家 更新时间:2023-11-01 06:20:03 25 4
gpt4 key购买 nike

我正在尝试使用以下教程(在 Swift 中!)为应用程序创建后端:

https://backendless.com/feature-2-registering-app-users-with-the-user-registration-api/#

但在 registerUser() 函数中,它告诉我:预期的成员名称在“.”之后Types.try({ () ->无效

其他一切正常。即使我删除此函数并执行 registerUserAsync(),也会创建用户。所以这不是框架导入问题。

这可能是 Swift1/2 问题吗?由于代码在 Swift1 (println(...))

感谢任何帮助

代码:

//  ViewController.swift
// F2RegisteredUsersSwift

import UIKit

class ViewController: UIViewController {

let APP_ID = "YOUR-APP-ID"
let SECRET_KEY = "YOUR-SECRET-KEY"
let VERSION_NUM = "v1"

var backendless = Backendless.sharedInstance()

override func viewDidLoad() {
super.viewDidLoad()

backendless.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM)

registerUser()
registerUserAsync()
}

func registerUser() {

Types.try({ () -> Void in

var user = BackendlessUser()
user.email = "spiday@backendless.com"
user.password = "greeng0blin"
user.setProperty("phoneNumber", object:"214-555-1212")

var registeredUser = self.backendless.userService.registering(user)
println("User has been registered (SYNC): \(registeredUser)")
},

catch: { (exception) -> Void in
println("Server reported an error: \(exception as Fault)")
})
}

func registerUserAsync() {

var user = BackendlessUser()
user.email = "green.goblin@backendless.com"
user.password = "sp1day"
user.setProperty("phoneNumber", object:"214-555-1212")

backendless.userService.registering(user,
response: { (var registeredUser : BackendlessUser!) -> () in
println("User has been registered (ASYNC): \(registeredUser)")
},
error: { (var fault : Fault!) -> () in
println("Server reported an error: \(fault)")
}
)
}

}

最佳答案

“try”是 Swift 2 中的保留字(用于错误处理)。如果您的 Swift 1 代码中有一个名为“try”的方法或函数,您最好重命名它。

关于ios - '.' 之后的 Swift/iOS/预期成员名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35451107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com