Problems with connections (IBActions)

So I have a problem with classes and connections, I have created a class inside of a class, it looked something like this:

class ExampleA: UIViewController {

     class ExampleB: UIViewController {

     }

}

So then when I created an IBAction inside of the class 'ExampleB', for some reason it won't connect and comes up with a 'Thread 1: signal SIGABRT', it looks something like this:


class ExampleA: UIViewController {

     class ExampleB: UIViewController {
          @IBAction func ExampleConnectionC(_ sender: Any) {
          }
     }

}

If you could explain to me why it would be much appreciated...


Kind regards,

-Exo-

Replies

AFAIU, it is because the nested class is not visible outside the enclosing class.

When you say :

So then when I created an IBAction inside of the class 'ExampleB', for some reason it won't connect

Do you mean you cannot connect in IB ?


How did you declare its UIViewController in IB ? Could you declare as ExampleB (I guess no): hence you cannot connect.

I have not tried, but may be you could set the action in code, using ExampleA.exampleConnectionC syntax


This thread could interest you for more explanations.

https://stackoverflow.com/questions/26806932/swift-nested-class-properties

In my code, the class 'ExampleA' is a UIViewController, and class 'ExampleB', is a UITableViewController, because I am trying to link 2 different ViewControllers. My objective is that when the user clicks on a button, it will set off a table in a different ViewController to add a column to it.

But why do you need to declare ExampleB inside ExampleA ?


Is it just for a testing purpose or have you a specific intent ?


Otherwise, get ExampleB declaration out of exampleA and everything will be simpler.

You have a lot of solutions to transfer data from one to the other:

- notification

- delegation

- in prepare segue