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
Post a Comment