ios - return from initializer without initializing all stored properties (self.ref is not initialized) -


when input code twitter app error return initializer without initializing stored properties code var ref: firdatabasereference! saying self ref not initialized

import foundation import firebasedatabase  struct meme {    var ref: firdatabasereference! var key: string! var username: string! var name: string! var tweetid: string! var tweettext: string! var tweetimageurl: string! var tweeterimageurl: string   init(username: string, memeid: string, memetext: string, memeimageurl: string, memerimageurl: string, name: string, key: string = ""){      self.username = username     self.name = name     self.memeid = memeid     self.memeimageurl = memeimageurl     self.memetext = memetext     self.memerimageurl = memerimageurl    }     init(snapshot: firdatasnapshot){      self.name = snapshot.value!["name"] as! string     self.memerimageurl = snapshot.value!["memerimageurl"] as! string     self.memetext = snapshot.value!["memetext"] as! string     self.memeimageurl = snapshot.value!["memeimageurl"] as! string     self.username = snapshot.value!["username"] as! string     self.name = snapshot.value!["name"] as! string     self.ref = snapshot.ref     self.key = snapshot.key }  func toanyobject() -> [string: anyobject]{      return ["name":name, "username":username, "memetext":memetext,"memeid":memeid,"memerimageurl":memerimageurl,"memeimageurl":memeimageurl] } 

}`

it's not clear objective if var required, should initialized default value within init

init() {    self.key = "some key"    self.username = "some user name" } 

alternately, change struct/class vars

struct meme {    var key = ""    var username = "" } 

and vars can init'ed on fly

var aaa = meme() aaa.key = "some key" aaa.username = "some username" 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -