Using a cell in another file in Swift

I would like to keep the content of a UITableView cell in a separate file as I do in Objective-c even in my TodayExtension Swift table in order to wire it to the storyboard. Yet when I try to do it, it complaints it cannot find the class of the cell; this is the function I use:


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
println(indexPath)
let cell = tableView.dequeueReusableCellWithIdentifier( TableViewConstants.cellIdentifier, forIndexPath: indexPath) as! TodayCell
return cell

todayCell is the class in another file it reports it cannot find:

import UIKit class TodayCell: UITableViewCell {
@IBOutlet var bus: UILabel
 @IBOutlet var stopAddress: UILabel! 
 @IBOutlet var destination: UILabel!
}

Importing the file, even if not needed according the the Swift documentation, moved the error in the import statement.

Answered by fbartolom in 8931022

I found the problem: Xcode forgot to add the new TodayCell file to the list of compile sources when I added it to the project. Once I manually did it everything worked fine - I had a funny horror trip in a list of errors in the MKStoreManager library, but all of them went away upon returning to the last commit.

Try this:

import UIKit
class TodayCell: UITableViewCell {
  @IBOutlet var bus: UILabel
  @IBOutlet var stopAddress: UILabel!
  @IBOutlet var destination: UILabel!
}


You have to split the import and the class statement either by a newline or a ";".

I did it, even if I got no errors and the main viewController had the import and class adjacent, but it keeps on being unable to locate TodayCell.

/Users/fbartolom/Documents/cocoa applications/inArrivoHD/ArrivalWidget/TodayViewController.swift:109:132: Use of undeclared type 'TodayCell'

/Users/fbartolom/Documents/cocoa applications/inArrivoHD/ArrivalWidget/TodayViewController.swift:131:33: Use of unresolved identifier 'TodayCell'

/Users/fbartolom/Documents/cocoa applications/inArrivoHD/ArrivalWidget/TodayViewController.swift:110:132: Use of undeclared type 'TodayCell'

/Users/fbartolom/Documents/cocoa applications/inArrivoHD/ArrivalWidget/TodayViewController.swift:132:33: Use of unresolved identifier 'TodayCell'

You could try deleting the derived data folder for the project. Perhaps the indexing got bugged.

Accepted Answer

I found the problem: Xcode forgot to add the new TodayCell file to the list of compile sources when I added it to the project. Once I manually did it everything worked fine - I had a funny horror trip in a list of errors in the MKStoreManager library, but all of them went away upon returning to the last commit.

How i do that? same problem here, having my NameTableViewCell correctly in storyboard, with custom class, and the same error happens. How do you did this manually ??

Using a cell in another file in Swift
 
 
Q