four-eyes
four-eyes

Reputation: 12394

Cannot connect View Controller to Swift file

I created a second view controller in the storyboard. I also created a new Swift-file with File - New - Cocoa..... Now I want to associate that Swift-file with the second view controller. So I highlight the second view controller, and click Show Identity Inspector. In Custom Class in the Class field I normally would add the Swift-file in order to create i.e. outlets. However, I cannot find the newly created Swift-file in there.

Thats the code from the new Swift-file

import UIKit

    class EditImageViewController: NSObject {

}

Why is that?

Upvotes: 2

Views: 1336

Answers (1)

Scriptable
Scriptable

Reputation: 19750

In your newly created Swift file. You need to declare a class which inherits from UIViewController.

Like:

class SomeViewController: UIViewController {

}

Then you will be able to connect IBOutlets and IBActions to this class.

If you are still having issues after your class inherits from UIViewController check the file inspector and ensure that the {your app name} target is checked (so that the file belongs to the correct module)

Upvotes: 1

Related Questions