Reputation: 5924
I am not an Obj C pro, but I should write some code in Objective C and bridge a Swift code to it. I success in importing the Generated Header to the .m file:
#import "<my_module>-Swift.h"
But when I try importing the same header to the .h file it throws this error:
BTW, I only want to add a public variable that instances from a Swift class to a specific obj c class. I've tried to put these lines at the .h and .m files:
@property (nonatomic, readwrite, strong) Card *card;
What should I do?
Upvotes: 1
Views: 173
Reputation: 118691
In your case, since all you need to do is declare a property of type Card*
, you don't actually need to import the header—you can just forward-declare the class with @class Card;
before using it.
Upvotes: 1
Reputation: 4891
If you want to reference a Swift class in an Objective-C header, you cannot #import
the *-Swift.h
file, but should rather use a forward declaration as described in https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html, see the section titled Referencing a Swift Class or Protocol in an Objective-C Header. This is basically what @jtbandes is suggesting in the comment.
One gotcha here: the Swift class you want to use in Objective-C must extend the NSObject class, directly or indirectly.
Upvotes: 0