ios - Cannot invoke initializer for type 'User' with an argument list of type '(snapshot: (DataSnapshot)) Swift 3 -


after update firebase pod got error :

cannot invoke initializer type 'user' argument list of type '(snapshot: (datasnapshot))'

and here code enter image description here

any idea solve ..???

func loaduserinfo(){      let userref = databaseref.child("users/\(auth.auth().currentuser!.uid)")     userref.observe(.value, with: { (snapshot) in          let user = user(snapshot: snapshot)         self.usernamelabel.text = user.username         self.usercountry.text = user.country!         self.userbiographytextview.text = user.biography!          let imageurl = user.photourl!          self.storageref.reference(forurl: imageurl).data(withmaxsize: 1 * 1024 * 1024, completion: { (imagedata, error) in             if error == nil {                 dispatchqueue.main.async {                     if let data = imagedata {                          self.userimageview.image = uiimage(data: data)                     }                 }             } else {                 print(error!.localizeddescription)             }         })      }) { (error) in         print(error.localizeddescription)     } } 

after update firebase 4.0.4 got error, here whole codes :

import foundation import firebase import firebasestorage import firebasedatabase import firebaseauth    struct authservice {     var databaseref: databasereference! {         return database.database().reference()     }     var storageref: storagereference! {         return storage.storage().reference()     }       // 1- creating signup function      func signup(username:string,email:string,country:string,password:string,biography: string, picturedata:nsdata!) {         auth.auth().createuser(withemail: email, password: password, completion: {(user, error) in             if error == nil {                  self.setuserinfo(user: user, username: username, country: country, password: password, biography: biography, picturedata: picturedata)             } else {                 print(error?.localizeddescription any)             }           })     }      // 2- create set user info function      private func setuserinfo(user: user!, username: string, country: string, password: string, biography: string, picturedata: nsdata!)     {          let imagepath = "profileimage\(user.uid)/userpic.jpg"          let imageref = storageref.child(imagepath)          let metadata = storagemetadata()         metadata.contenttype = "image/jpeg"          imageref.putdata(picturedata data, metadata: metadata) {(newmetadata, error) in              if error == nil {                  let changerequest = user.profilechangerequest()                 changerequest.displayname = username                  if let photourl = newmetadata!.downloadurl() {                     changerequest.photourl = photourl                 }                  changerequest.commitchanges(completion: { (eroor) in                     if error == nil {                         self.saveuserinfo(user: user, username: username, country: country, password: password, biography: biography )                         } else {                         print(error?.localizeddescription any)                     }                  })              } else {                 print(error?.localizeddescription any)             }              }       }      // 3- save user info in firebase      private func saveuserinfo(user: user!, username: string, country: string, password: string, biography: string)     {         let userinfo  = ["email": user.email!, "username": username, "country": country,"biography": biography, "uid": user.uid, "photourl": string(describing: user.photourl!)]          let userref = databaseref.child("users").child(user.uid)         userref.setvalue(userinfo)  { (error, ref) in             if error == nil {                 print("user info saved successfully")                 self.login(email: user.email!, password: password)               } else {                 print(error?.localizeddescription any)             }           }        }        // logging user in function      func login(email: string, password: string) {         auth.auth().signin(withemail: email, password: password, completion: { (user, error) in             if error == nil {                 if let user = user {                     print("\(user.displayname!) has logged in successfully")                      let appdel: appdelegate = uiapplication.shared.delegate as! appdelegate                     appdel.loguser()                 }                }             else {                 print(error?.localizeddescription any)              }          })     }      } 

now have 2 errors :

here errors

i tried update profilechangerequest() createprofilechangerequest() didn't help

here user class:

import foundation import firebase import firebasedatabase  struct user {     var username: string!     var email: string?     var country: string?     var biography: string?     var photourl: string!     var uid: string!     var ref: databasereference?     var key: string?       init(snapshot: datasnapshot) {          key = snapshot.key          ref = snapshot.ref          username = (snapshot.value! as! nsdictionary)["username"] as! string          email = (snapshot.value! as! nsdictionary)["email"] as? string          country = (snapshot.value! as! nsdictionary)["country"] as? string          uid = (snapshot.value! as! nsdictionary)["uid"] as! string          biography = (snapshot.value! as! nsdictionary)["biography"] as? string         photourl = (snapshot.value! as! nsdictionary)["photourl"] as! string      }   } 

i think user class clashing with firuser class changed firuser user in 4.x sdk. try renaming user class localuser , see if helps, if there's problem


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -