ios - Social network app gives error on a return line -


i finalizing social media application , consistently having same error regarding "username" of user during launch process of application (app running, user logged in, , next view controller fails come , crashes giving exc_bad_instruction).

i thinking might adata base problem had the profile picture, however, user name in database registered user email , password.

the code of section error in:

import foundation import firebase import firebasedatabase  class post {  private var _username: string! private var _userimg: string! private var _postimg: string! private var _likes: int! private var _postkey: string! private var _postref: databasereference!  var username: string {     return _username }  var userimg: string {     return _userimg }  var postimg: string {     {         return _postimg     } set {         _postimg = newvalue       } }  var likes: int {     return _likes }  var postkey: string {     return _postkey }  init(imgurl: string, likes: int, username: string, userimg: string) {     _likes = likes     _postimg = imgurl     _username = username     _userimg = userimg }      init(postkey: string, postdata: dictionary<string, anyobject>){      _postkey = postkey      if let username = postdata["username"] as? string {         _username = username     }      if let userimg = postdata["userimg"] as? string {         _userimg = userimg     }      if let postimg = postdata["imageurl"] as? string{         _postimg = postimg         }     if let likes = postdata["likes"] as? int {         _likes = likes         }     _postref = database.database().reference().child("posts").child(_postkey)  }  func adjustlikes(addlikes: bool) {      if addlikes {          _likes = likes + 1     } else {          _likes = likes - 1     }      _postref.child("likes").setvalue(_likes) }  }  

the line error occurs:

return _username 

i puzzled issue be. have looked @ iboutlets, removing , adding new users. appreciate help.

in init(postkey:postdata:) constructor it's not guaranteed _username property set. however, public username property of non-optional type string. assumption username getter tries forcefully unwrap nil value.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -