随着最新beta版本中Swift的更新,这不再适用,我很难过。我可能需要添加其他内容,我们已尝试将let
更改为var
并向!
和recordType["username"]
添加password
。我是新手,所以任何方向都会非常感激!
import UIKit
import CloudKit
class LoginViewController: UIViewController {
@IBOutlet weak var username: UITextField!
@IBOutlet weak var password: UITextField!
let publicDatabase = CKContainer.default().publicCloudDatabase
override func viewDidLoad(){
super.viewDidLoad()
}
@IBAction func LoginTapped(sender: AnyObject){
var recordType = CKRecord(recordType: "Login")
recordType["username"] = username.text <-Cannot assign value
recordType["password"] = password.text <-Cannot assign value
publicDatabase.save(recordType) {
(record, error) in
if error == nil {
print("Created Successfully")
}
else {
print(error?.localizedDescription)
}
}
}
}
答案 0 :(得分:4)
尝试:
recordType["username"] = username.text! as NSString
recordType["password"] = password.text! as NSString