2

I wrote two swift files.

// ViewController.swift
import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

and

// ViewController2.swift
import UIKit

class ViewController2: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

My Main.storyboard looks like this.

Main.storyboard

When I run these programs, I get

2015-11-14 01:17:46.705 hoge[23606:1084831] Unknown class ViewController in Interface Builder file.
2015-11-14 01:17:49.311 hoge[23606:1084831] Unknown class ViewController2 in Interface Builder file.

How can I solve them? Source codes are here.

I'm using XCode Version 7.1.1 (7B1005).


SOLVED: I moved the directory to ~/Desktop, and finally it runs. Very strange...

The same issue reported in Unknown class in Interface Builder file. Xcode 6 and Swift

Community
  • 1
  • 1
kyon
  • 183
  • 1
  • 3
  • 12

4 Answers4

4

Select your view controller in you IB and give the correct class name in the custom class field . Remove the view controller and just type in the class name, xcode should automatically suggest the available Class name. Then it should be fine!!!

enter image description here

This was the error :

enter image description here

Then I removed the class name view controller, and re entered it again, then I didnt get the error:

enter image description here

If you look carefully, module name is changed to hoge!!! Previously it was none!!!

Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109
  • why the downvote? I downloaded his source code and run the project. The only issue lies in the IB custom class field. – Teja Nandamuri Nov 13 '15 at 16:49
  • The custom class field takes a class not a file name. Answer is wrong it works in your case because there happens to be a class called `viewController` so instead of a crash it's a bug with the view pointing to the wrong class. – Mika Nov 13 '15 at 16:51
  • May be thw wording is wrong. I meant the class name only. Thanks for the comment!!! – Teja Nandamuri Nov 13 '15 at 16:53
  • BTW the source code link he provided in the question doesnt have the problem as you stated in your answer !!! @Mika – Teja Nandamuri Nov 13 '15 at 16:55
  • Then your screenshot should show `viewController2` and he needs to fix the class :) – Mika Nov 13 '15 at 16:56
  • Then your screenshot should show `viewController2` and he does not need to fix the class :-P – Mika Nov 13 '15 at 16:57
  • He named it correctly for the view controller 2, did u look into the source code ? @Mika – Teja Nandamuri Nov 13 '15 at 17:02
  • OK OK I removed the vote from your edited answer... I just answered the question he asked here. I did not download the project... – Mika Nov 13 '15 at 17:11
  • im glad u mentioned the reason you downvote....i really appreciate that!!! I edited my answer, and u took ur down vote back!!! Everything is fair!!! – Teja Nandamuri Nov 13 '15 at 17:13
  • I got scared... Phillip is on your team :) – Mika Nov 13 '15 at 17:16
  • Was jocking see his comment on my answer! – Mika Nov 13 '15 at 17:18
  • Even though I type like ```ViewContr``` into Custom Class - Class, XCode doesn't suggest me anything... And of course Module is ```None```` after I type the class name by myself. – kyon Nov 14 '15 at 01:10
1

Firstly, you need create 2 class ViewController and ViewController2 as like imageenter image description here

And then link it like image

enter image description here

For example code:

// ViewController1.swift
import UIKit
class ViewController: UIViewController {
    //your code here...
}

and

// ViewController2.swift
import UIKit
class ViewController2: UIViewController {
    //your code here...
}

Hope i can help u to resolved this problem.

Mika
  • 5,807
  • 6
  • 38
  • 83
Cuong Nguyen
  • 980
  • 2
  • 9
  • 29
1

When you assign the custom class name in Interface Builder, choose a module name too. If it's left as "none", you'll get the results you describe.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57
0

both of your classes - although your swift files are named differently - are called ViewController. maybe that is the problem?!

after correcting that you should remove the custom classes from the viewcontrollers in storyboard, build the project, insert the custom classes again and build again.

André Slotta
  • 13,774
  • 2
  • 22
  • 34