John Brunner
John Brunner

Reputation: 2872

Xcode, can't find my class which I had created

I'm playing arround with Xcode (for iOS) and added a View Controller to my Storyboard. Now I've created a Class (File -> New File -> Objective-c Class) and made that a subclass of UIViewController. Now the .h and .m files are generated and listed on the left side in Xcode, but when I want to change the "custom class" of my added View Controller there is nowhere my class which I had generated. Am I doing something wrong?

Thanks in advance.

Upvotes: 24

Views: 24874

Answers (7)

Saad Chaudhry
Saad Chaudhry

Reputation: 1412

There are multiple reasons and solutions....

#1

  • Select project icon in "Project Navigator".
  • Then go to your Target's Build Phases -> Compile Sources.
  • Finlly, click the + button, and add your *.m or *.swift file.

#2

In one case, the same file was added multiple times to project:

  • Remove all instance of the file.
  • Add file back to project (once).
  • Finally, select the file in "Project Navigator", and in the "File inspector" on the right, look at the "Target Membership" section. The app target (not the Test target) should be checked, similar to this:

right membership

#3

ANOTHER WAY IS

  • Save all my work;
  • Just quit Xcode & load it again;
  • Then I was able to insert the new outlet connection successfully.

#4

  • Close the project you are working on with.
  • Delete the【DerivedData】folder of you project.

    Said folder may be:

    • Inside your project's folder,
    • Or, inside ~/Library/Developer/XCode/DerivedData/(your project)/
    • Or, somewhere else that was setup by you.
  • Restart you project.

#5

  • Simply Clean your Project,
  • Then Build Again,
  • Finally, check and/or run.

Upvotes: 15

dorian
dorian

Reputation: 847

Just a quick advice in case you are about to give up: Do check that the item you have in the storyboard is compatible with the custom class you created that you are trying to assign. For example, you cant choose a UIView based class if you have a UIImageView as a component in your storyboard. In that case, it simply wont appear in the dropdown list.

Upvotes: 2

hbk
hbk

Reputation: 11184

Solution for my situation - just close all other xCode windows (i got opened few projects at same time).

Also sometimes help cleaning of project.

Upvotes: 0

user986408
user986408

Reputation:

You don't have to completely quit Xcode. Just close all your Storyboard tabs completely and reopen a new tab by double clicking on it.

Upvotes: 0

mad pig
mad pig

Reputation: 788

I've had the same problem. Quitting and opening Xcode will make the Class show up in the list.

edit: I've also recently found pasting the Class name will work in 5.02 Xcode.

Upvotes: 44

Eduardo Leal
Eduardo Leal

Reputation: 151

I had the same problem. But I discovered that I was clicking inside the "window of storyboard" and was selecting a view, so with no viewController related to. My solution was: to click inside the owner, or the viewController from the left list, and then change the custom class.

Upvotes: 15

HeadNinja
HeadNinja

Reputation: 69

I'm not sure what you mean by " but when I want to change the "custom class" of my added View Controller there is nowhere my class which I had generated ". It seems like you are trying to make the UIViewController in your storyboard to be of the same type of your custom UIViewController subclass.

If that's the case, then select your UIViewController (make sure you're not selecting the UIView within that UIViewController)

With the UIViewController selected, open the right hand view and open the Custom Class tab, then start typing in the name of your UIViewController subclass.

If that isn't working, then you need to ensure that the in the .h file you say:

@interface MyCustomUIViewController : UIViewController

If it still isn't working, ensure that in storyboard you are selecting the UIViewController that you put down. If you are trying to fill in the Custom Class of a UIView with a UIViewController subclass, it shall not work!

If it all still doesn't work, try COMMAND+SHIFT+K, and COMMAND+B to Clean and Build! Good luck.

Upvotes: 3

Related Questions