Search code examples
iosswiftexc-bad-access

Calling function on subclass of UILabel


I can't really understand why I am getting this error when I call a function on a subclass of UILabel. I have in AppDelegate

class CascadingLabel: UILabel {
func cascade(){
    DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
            self.alpha = 1
        }
    }
func initializeText(){
    print("[OUT21] Init")
}
}

In ViewController,

@IBOutlet weak var Intro1: CascadingLabel!
 func initializeText(){
    Intro1.initializeText() //Here I am getting error!
}
override func viewDidLoad() {
    super.viewDidLoad()
    print("[OUT21] OpeningScreen opened")
    initializeText()
}

The app crashes, yielding error:

Thread 1: EXC_BAD_ACCESS (code=2, address=0x1b3900ec8)

UPDATE ANSWER: Thanks to @ChristianAbella for the answer here. I didn't indicate the class in the Storyboard.


Solution

  • I think you are getting following error

    enter image description here

    Everything is fine just assign your class name to UILabel in storyboard

    enter image description here