kyon
kyon

Reputation: 183

Unknown class XXXXX in Interface Builder file

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

Upvotes: 2

Views: 2461

Answers (4)

Teja Nandamuri
Teja Nandamuri

Reputation: 11201

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!!!

Upvotes: 4

Phillip Mills
Phillip Mills

Reputation: 31016

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.

Upvotes: 1

Cuong Nguyen
Cuong Nguyen

Reputation: 990

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.

Upvotes: 1

André Slotta
André Slotta

Reputation: 14030

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.

Upvotes: 0

Related Questions