0

Although I have followed and tried everything from This Thread and read all of Apple's Guide of Swift-ObjC interoperability, I'm unable to recognize or use Swift fies in my project.

I have created a Swift file that declares/defines a class called TorusView that inherits from UIView. I've tried to gain access to this class in another class MenuView by importing the bridging header, importing the Swift class, importing the class with the syntax *-swift.h (which seems to now be *.swift.hin Xcode7.2). I've made all of the modifications to my target build settings recommended in that lengthy Stack question and a variety of others from google searches.

Nothing I've tried has allowed me to create a TorusView objective in my objective-C class.

Community
  • 1
  • 1
Alex Bollbach
  • 3,730
  • 2
  • 25
  • 61

2 Answers2

0

You need to import a header file YourAppName-Swift.h, it contains all the public (and internal if same target) declared types in Swift.

feb
  • 1,648
  • 1
  • 10
  • 7
  • Does the public interface of your Swift class include anything not supported in ObjC, like generics or Swift enums? – feb Mar 02 '16 at 20:13
  • No it is just an empty class that inherits from UIView – Alex Bollbach Mar 02 '16 at 20:18
  • Have you run the app to make sure the header is generated? – sschale Mar 02 '16 at 20:19
  • Now I am getting errors all throughout my swift file on every line. Xcode is forcing me to add semi-Colons after my import statements. – Alex Bollbach Mar 02 '16 at 20:19
  • I ran/built the app many times. (I originally accidentally lost my target and created a new one, so now my project name appears to be DraWave_Iphone_Target).. There is a file in my main bundle folder called `DraWave_Iphone_Target-Bridging-Header.h` and I've checked my derived data dir and buried in there is a file `DerivedSources/buildDraWave_Iphone_Target-Swift` – Alex Bollbach Mar 02 '16 at 20:23
  • I've gone through and changed all the recommended build settings such as `define Modules` at the project and target levels. I've tried all permutations and included all variations of these files. Nothing has worked. It even looks like the Apple documentation on Obj-C/Swift mix and match is out of date with what my xcode is doing. – Alex Bollbach Mar 02 '16 at 20:24
0

first: Build Settings --> defines module --> YES.

second:Product Module Name -->YOUR project NAME.

last:improt "YOUR project NAME-Swift.h" in your Object-c file

like this: enter image description here

woodruff
  • 16
  • 2