I saw a lot of posts about this error in Xcode but all of them are quite old. I’m learning how to code in Swift and I’m following the instruction of book.
My Xcode is version 12.5.1. The goal of this app is to display a list of quotes (string) and when I tap on one of them, display a new view that has as a title the quote.
I have a very simple storyboard. There is a TableView
with a segue
to a View
. I created a new Cocoa
file for tableview. TableView
is working.
I connect the TableView with the View.
I repeated the some process for the View. I added a new Cocoa file called QuoteDetailViewController
, click on top of the view and in the Class I selected from the list the file.
When I run the application in the iPhone 11 simulator, the view doesn’t have any quote as title. I put a breakpoint in the code connected to the TableView and the app stops there. If I put a breakpoint in the QuoteDetailViewController
nothing happens but I see an error in the output
2021-08-11 19:13:17.215204+0100 QuoteApp[80238:4055489] [Storyboard] Unknown class QuoteDetailViewController in Interface Builder file.
The QuoteDetailViewController
is very basic.
import UIKit
class QuoteDetailViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let quoteViewController = segue.destination as? QuoteDetailViewController {
if let selectedQuote = sender as? String {
quoteViewController.title = selectedQuote
}
}
}
}
I tried to build again and again the app. I tried to Clean Build Folder and build again. I tried to recreate the View and the code. After all of that, nothing changed. The error is still there.
The source code is on GitHub.
Update
If I click on the arrow at the end of Class
and just before the dropdown, Xcode opens the file I expect to be opened.
2
Answers
So, I said that in the
QuoteDetailViewController
I have this code.The error was that the function
prepare
must be in theQuoteTableViewController
.Select the
QuoteDetailViewController
, open Side Inspector view and Update theTarget Membership
same asQuoteTableViewController
Select the controller On the Storyboard, and Add it to the module.
Check Screenshots for reference: