ios - performSegueWithIdentifier: unexpectedly found nil while unwrapping an Optional value -


i wish allow selecting row whereby, action outlined below occur:

override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {      tableview.deselectrowatindexpath(indexpath, animated: true)          // ensure controller knows dataset pull from,         // detail view correct         var friendchat: friend!          friendchat = mappedfriends[indexpath.row]          // set conditional cases: if friend chat, if user friend request if not user can invite them:         if(friendchat.statussort == 2) {              var controller : individualchatcontroller!              print(friendchat.name)              controller.friendchat? = friendchat             controller.senderid? = global.sharedinstance.userid             controller.senderdisplayname? = global.sharedinstance.username              self.performseguewithidentifier("showindividualchat",sender: controller)          } else             if (friendchat.statussort == 1) {              print("can invite friend")          } else if (friendchat.statussort == 0) {              print("invite feast")          }  } 

however, during assignment, of:

            controller.friendchat? = friendchat             controller.senderid? = feastglobal.sharedinstance.userid             controller.senderdisplayname? = feastglobal.sharedinstance.username 

the error: fatal error: unexpectedly found nil while unwrapping optional value appears.

why occur? how can alleviated?

you declaring, not assigning value variable controller here:

var controller : individualchatcontroller! 

you making promise not nil setting type implicitly unwrapped optional exclamation mark, i.e. individualchatcontroller!

however, promise not kept, because no value assigned , in fact nil @ time code runs:

controller.friendchat? = friendchat 

this why getting fatal error.

the fix assign value controller var when declare it. example:

var controller:individualchatcontroller = individualchatcontroller() 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo