Reputation: 87
I'm updating an old Objective-C app to include an Watch Extension written in Swift.
I was sure to change the Embedded Content Contains Swift Code default:
I have the following header file:
#import <Foundation/Foundation.h>
@interface Elements : NSObject
// designated initializer
-(instancetype)initWithElement:(NSString *)atom
AndNumber:(NSNumber *)number;
+(NSDictionary *) elementInfo;
+(NSArray *) atomArray;
@property (strong, nonatomic) NSNumber *mass;
@property (strong, nonatomic) NSString *name;
@property (strong, nonatomic) NSString *ChemicalName;
@end
How can I use the above Elements Object, within my Swift Watch extension?
Now I have the following error:
Upvotes: 2
Views: 1486
Reputation: 286
You need to have a bridge header file (Xcode will ask to create it for you first time you try to mix obj-c with swift). If you didn't let Xcode create it for you, you will have to create it yourself and then go to build setting for all targets and set under swift compiler -> code generation -> add to 'Objective-C Bridging Header': Bridging-Header-FileName.h. Once header is ready, import all Obj-C header you need to access in Swift.
Upvotes: 5
Reputation: 1295
To use Objective-C code in your Swift code you need to add a Objective-C Bridging Header to your project.
Using Swift with Cocoa and Objective-C
Upvotes: 0