Search code examples
iosswiftexc-bad-access

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


I am very new to coding and i have decided to begin learning swift. I have encountered a problem with a bug apparently and my app is not running properly. I have attached all the code in my project. Hope anyone can help. Thanks In advance

ContactsTableViewController

ContactsTableViewController2

Contacts.swift (file)

StoryBoard


Solution

  • Remove the lines where object creates inside a class like

    var thirdContact = Contacts() 
    

    in Contacts class. You can't create object inside same class, it leads to endless loop. Stack trace example

    #1  0x000000010b6c3f88 in Contacts.init(name:phone:) at Contacts.swift:12
    #2  0x000000010b6c3e11 in Contacts.__allocating_init(name:phone:) ()
    #3  0x000000010b6c415a in Contacts.init(name:phone:) at Contacts.swift:22
    #4  0x000000010b6c3e11 in Contacts.__allocating_init(name:phone:) ()
    #5  0x000000010b6c415a in Contacts.init(name:phone:) at Contacts.swift:22
    ...