0
votes

Initializer for conditional binding must have Optional type, not '() -> String?

How to treat this error?

enter image description here Code:

func loadViewFromNib() -> UIView? {
    let xibName = getXibName()

    let bundle = Bundle(for: type(of: self))
    let nib = UINib(nibName: xibName!, bundle: bundle)
    return nib.instantiate(
        withOwner: self,
        options: nil).first as? UIView
}

func getXibName() -> String? {
    return nil
}
1
Please copy paste the code. You are free to post the screenshot to show the error you get. But please include a copy of the code, so that it is easier for people to respond using your code. - Rakesha Shastri
Better show your code also as text. Isn't that Xcode is digging old historic errors? Have you tried Clean Build Folder or restarting Xcode or restarting your Max? - OOPer
Clean your code, Delete derived data or restart xcode - Prashant Tukadiya

1 Answers

0
votes

Thanks to OOPer's comment:

Xcode -> Product -> Clean Build Folder

enter image description here