无法指定'String'类型的值?输入'CKRecordValue'

时间:2016-08-24 22:56:42

标签: swift cloudkit swift3

随着最新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)
            }
        }
    }
}

1 个答案:

答案 0 :(得分:4)

尝试:

recordType["username"] = username.text! as NSString
recordType["password"] = password.text! as NSString