skip to Main Content

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

2

Answers


  1. class ViewController: UIViewController {

    @IBOutlet weak var WelcomeTo: UILabel?
    @IBOutlet var Language: UILabel?
    

    strong text

    Login or Signup to reply.
  2. Try to unwrap it in a guard let statement like that:

    func valueInit(WelcomeToString: String, LanguageString: String) {
        
        var testValue = WelcomeToString
        guard let myTestValue = WelcomeTo?.text else { return }
        
        testValue = myTestValue
     
        print(testValue)
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search