0

I just included certain firebase pods in my project , before that my project had no errors and it was running just fine , but when I added this code

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    handleNotAuthenticated()
}
private func handleNotAuthenticated(){
    if Auth.auth().currentUser == nil{
    //            Show login
        let loginVC = LoginControllerViewController()
        loginVC.modalPresentationStyle = .fullScreen
        present(loginVC,animated: false)
            }
    //        else do nothing
}

I got an error in my loginVC , following is my loginVC Code:-

override func viewDidLoad() { super.viewDidLoad()

    Label.font = UIFont(name: "LobsterTwo-Bold", size: 35) //I got that fatal error here 
    LoginOutlet.titleLabel?.font = UIFont(name: "LobsterTwo-Bold", size: 25)
    DontHaveButtonO.titleLabel?.font = UIFont(name: "Georgia", size: 20)
    
    // Do any additional setup after loading the view.
}

I tried displaying an empty(new VC) it worked fine but , whenever I use this LoginVC it gives me that above error , I tried cleaning build folder and re-adding the fonts folder ,please help me

  • The outlet is not connected. – vadian Sep 18 '20 at 07:25
  • 1
    Does this answer your question? [What does "Fatal error: Unexpectedly found nil while unwrapping an Optional value" mean?](https://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-valu) – vadian Sep 18 '20 at 07:26
  • Hey @vadian, they are all connected, I also tried commenting the code inside viewDidLoad() but then the loginVC Shows a black screen nothing else –  Sep 18 '20 at 08:17
  • If you get the crash in this particular line then `Label` is `nil` or the font doesn't exist. – vadian Sep 18 '20 at 08:24
  • Hey @vadian, I actually commented everything in the viewDidload() and tested than also it shows me a black screen instead of original LoginviewController, and when I set My loginVC as initailViewController and than I test it, it works perfect –  Sep 18 '20 at 08:36
  • Are you using storyboard? If yes you have to instantiate the controller. The default initializer creates a new instance which is not the instance in the storyboard. – vadian Sep 18 '20 at 08:59
  • @vadian , Yes I am using storyboard , Can you please Explain a little deep ? that what is the solution –  Sep 18 '20 at 10:43
  • You have to call [instantiateViewController(withIdentifier:)](https://developer.apple.com/documentation/uikit/uistoryboard/1616214-instantiateviewcontroller) on the storyboard to get the instance in the storyboard. Please search, that's a very common method. – vadian Sep 18 '20 at 11:54

1 Answers1

0

Try this code, working for me

@IBOutlet weak var Label: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        Label.font = LobsterTwo.bold.font(size: 50)
    }


}

public enum LobsterTwo: String {
    case bold = "LobsterTwo-Bold"
    case boldItalic = "LobsterTwo-BoldItalic"
    case italic = "LobsterTwo-Italic"
    
    public func font(size: CGFloat) -> UIFont {
        return UIFont(name: self.rawValue, size: size)!
    }

StoryBoard screenshot

enter image description here

Simulator