因此,假设用户注册完成(此代码已经正确),并且下一个窗口要求用户输入个人信息(教育等),您如何编码该信息进入用户个人资料下的Firebase。
我已经完成了注册页面,并且在那里创建的用户已经转到firebase。
这是我注册后的页面内容。没有错误,但显然不完整。
import UIKit
import Firebase
import CoreFoundation
import AVFoundation
import SwiftKeychainWrapper
import FirebaseDatabase
class FeedVC: UITableViewController {
override func viewDidLoad() {
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Sign Out", style: .plain, target: self, action: #selector(signOut))
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
post()
}
//override func didReceiveMemoryWarning() {
// super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
// }
// MARK: - Table view data source
//override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
//return 1
// }
// override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
//return 5
// }
//override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// return UITableViewCell()
//}
func post() {
let MainFunInterest = "MainFunInterest"
let SomethingInterestingIhaveRead = "SomethingInterestingIhaveRead"
let JobOrEducation = "JobOrEducation"
let WhatIamConsideringBuying = "WhatIamConsideringBuying"
let post : [String : AnyObject] = ["MainFunInterest" : MainFunInterest as AnyObject,
"SomethingInterestingIhaveRead" : SomethingInterestingIhaveRead as AnyObject,
"JobOrEducation" : JobOrEducation as AnyObject,
"WhatIamConsideringBuying" : WhatIamConsideringBuying as AnyObject]
let databaseRef = Database.database().reference()
databaseRef.child("personal info").childByAutoId().setValue(post)
}
@objc func signOut (_sender: AnyObject) {
KeychainWrapper.standard.removeObject(forKey: "uid")
do {
try Auth.auth().signOut()
} catch let signOutError as NSError {
print ("Error signing out: %@", signOutError)
}
dismiss(animated: true, completion: nil)
}
}
我可以退出页面。当我当前注册时,进入firebase的只是用户希望输入的股票描述(例如,“教育”已在firebase中注册,而不是用户应输入的内容。
答案 0 :(得分:0)
我看到您使用FirebaseDatabase,但是我忘记了这是否是新的FirebaseFirestore。无论如何,在这种情况下,您将需要阅读更多与Firebase数据库相关的文档来创建自己的数据库查询,或者您需要先从“教育”中读取数据,然后编写自己的write,update,delete方法来处理数据更改,然后重新发布或更新它们。 希望能有所帮助!