Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Swift classes inherited from Objective C libraries code in Objective C code

I'm working on a Swift project, using couple of ObjC libraries. One of them is SWTableViewCell. My app's lists' cells inherit from SWTableViewCell, a subclass of UITableViewCell that adds swiping action on cells.

Libraries are added with cocoapods.

I want to import some Swift code into ObjC, within my main project. The project-Swift.h is being generated as it should (every Swift class inheriting from NSObject, annotated as @objc is being included), but it contains errors:

project-Swift.h:135:31: Cannot find interface declaration for 'SWTableViewCell', superclass of 'MySWTableViewCell'; did you mean 'UITableViewCell'?

How to remedy this situation? I need the header to be generated properly in order to use Swift classes in ObjC My goal is either to ignore these classes, or let XCode that it needs to import additional header during project-Swift.h

like image 231
darekxan Avatar asked Jun 16 '26 14:06

darekxan


1 Answers

This should solve your problem:

  1. Create a bridging header file in you project: File > New > File > (iOS or OS X) > Source > Header File
  2. In your Objective-C bridging header file, import the needed Objective-C headers you want to expose to Swift: in your case you need #import "SWTableViewCell.h"
like image 88
Ivan Rigamonti Avatar answered Jun 19 '26 04:06

Ivan Rigamonti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!