我无法理解错误究竟是什么告诉我的。我尝试使用self
并更改类来修复它。仍然无济于事。需要一份指南,以帮助了解我错过了什么或做错了什么。
import UIKit
import Foundation
import Firebase
extension LoginController: UIImagePickerControllerDelegate,UINavigationControllerDelegate{
func handleRegister(){
guard let email = emailTextField.text, let password = passwordTextField.text, let name = nameTextField.text
else {
print("This form is not valid")
return
}
Auth.auth().createUser(withEmail: email, password: password) { (self, error) in
if error != nil {
print(error!)
return
}
guard let uid = self?.uid else{
return
}
//sucessfully authenticated user
let storageRef = Storage.storage().reference()
// On the following line
if let uploadData = UIImagePNGRepresentation(self.profileImageView.image!) {
storageRef.putData(uploadData, metadata: nil, completion: { (metadata, error) in
if error != nil{
print(error)
return
}
})
}
let ref = Database.database().reference(fromURL: "https://bbooks-96cac.firebaseio.com/")
let userReference = ref.child("user").child(uid)
let values = ["name": name, "email": email]
userReference.updateChildValues(values, withCompletionBlock: {
(err, ref) in
if err != nil {
print(err)
return
}
// print("Saved user successfully into firebase DB")
})
}
dismiss(animated: true, completion: nil)
}
}
答案 0 :(得分:3)
首先,你滥用了术语Auth.auth().createUser(withEmail: email, password: password) { (self, error) in
(我很惊讶这里没有错误)。您需要一个更好的变量名称:
self
我会在此处及以下内容中将user
更改为Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
:
user
其次,if let uploadData = UIImagePNGRepresentation(user!.profileImageView.image!) {
是一个可选项,因此您需要打开它:
import urllib.request
def my_downloader(url, filename = None):
running_total = 0
def my_reporthook(count, size, total):
nonlocal running_total
running_total += size
print ("{}%".format(100*running_total//total))
return urllib.request.urlretrieve(url, filename, my_reporthook)
print (my_downloader('https://www.gutenberg.org/files/55146/55146-h.zip'))