I am new to swift, I am writing an app which needs to change images in the storyboard. i have written a function to change images in the image view. In the function there is an if condition the image should be changed when the if condition is satisfied, but i got "unexpectedly found nil while unwrapping optional value" error when if condition is executed.
import UIKit
import MessageUI
import Foundation
import CoreLocation
class ViewController: UIViewController {
@IBOutlet var F_IMG: UIImageView!
@IBOutlet var FL_IMG: UIImageView!
@IBOutlet var FR_IMG: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
TimeService.initial(viewcontroller: self)
}
public func showImages(){
var type: String = Otherclass.gettype()
setImageForType(type:type)
}
public func setImageForType(type:String){
if (type == "NONE"){
DispatchQueue.main.async {
self.F_IMG.image = UIImage(named: "r_f")
}
"The showImage() function is called in another class."
I have the image in the bundle, but my UI is not getting updated and it always shows the error "unexpectedly found nil while unwrapping optional value"