8

I am programming the ToDoList Objective-C Tutorial from Apple, but try to do it in Swift. (Tutorial)

Now that I am ready, when I run the Application, I get the error:

Unknown class AddToDoItemViewController in Interface Builder file in Swift.

In this thread, somebody solved a, as I think similar Problem with [MyClass class] in Objective-C. Is there a similar way to do this in Swift?

Cœur
  • 32,421
  • 21
  • 173
  • 232
McLawrence
  • 3,560
  • 5
  • 31
  • 44
  • Do you have a Swift class named `AddToDoItemViewController`? – Craig Otis Jul 27 '14 at 17:12
  • 1
    I ran into a similar issue (Xcode 6 Beta 6). I had a view controller (in a storyboard) with a custom class. This was discussed here: http://stackoverflow.com/questions/24924966/xcode-6-strange-bug-unknown-class-in-interface-builder-file @grfs's answer (accepted answer at time of writing) worked for me. – Duncan Smith Aug 26 '14 at 16:43

3 Answers3

38

I found that on a lot of my Swift Controllers there's a new Module Option which was set to None Failure

So to fix it just set the Class to a different one and then set it back. That gave me this

enter image description here

hdost
  • 824
  • 12
  • 21
1

A similar line in swift would be AddToDoItemViewController.self. All that really matters is you call your view controller from swift code so the linker knows to include that file.

Connor
  • 60,945
  • 26
  • 140
  • 138
  • thanks for your help. But somehow this doesn't solve the problem... Where do I have to insert this code. Allways get the error: expected declaration. – McLawrence Jul 27 '14 at 21:12
  • You can add it almost anywhere. An easy place to put it would be in AppDelegate inside `func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool` – Connor Jul 27 '14 at 21:14
  • @connor Rather than having to reference the class in code, surely it's not the default for the linker to optimize out these classes? Is it possible this is similar to a missing "-all_load -ObjC" issue? ie. http://stackoverflow.com/a/6092090/88111 – Craig Otis Jul 27 '14 at 21:25
1

I ran into this situation when I made a mistake and used a different name in the @OBJC statement than my declared class name.

Dan
  • 322
  • 3
  • 9