I've been working on a hard-coded language switcher for my app, where I have a xib file, where when I tap on a cell, it changes the language of the app, however I have a label that has the text "Welcome to" which will not register at all. In the elements inspector tool, I have added the text "Welcome to" (I even edited the font for reference) and every time I try to edit the title in any way I get the error - "Fatal error: Unexpectedly found nil while unwrapping an Optional value". I am begging you guys for a fix!
here is how it looks:
class ViewController: UIViewController {
@IBOutlet weak var WelcomeTo: UILabel?
@IBOutlet var Language: UILabel?
...
/// *when the cell is tapped on, this registers*
func valueInit(WelcomeToString: String, LanguageString: String) {
var testValue = WelcomeToString
testValue = (WelcomeTo?.text!)!
print(testValue)
}
Im begging you, do not ask "IS IT CONNECTED!". My outlet is more attached to my view controller than my arm is to my body so I'm begging you not to even try asking...
Tried removing and adding "Weak" before the outlet. Didn't help at all.
Tried adding the languages to my main file (instead of holding them in another file). Didn't help at all
Tried every solution here - IBOutlet is nil, but it is connected in storyboard, Swift. Didn't help at all
@IBOutlet weak var WelcomeTo: UILabel!
. Maybe not related to your issue but you don’t have to force unwrap the property every time you access it if you declare it like this.(WelcomeTo?.text!)!
will crash ifWelcomeTo
isnil
or its text isnil
. Please clarify which one it is:print("label: \(WelcomeTo)"); print("text: \(WelcomeTo?.text)")
Your label might be correctly connected, but maybe you don't init the ViewController correctly, ie not with the xib and its outlets.print("label: \(WelcomeTo!)")
with a question mark if needed.