To use Swift class in Objective C , follow given steps :
1. Create one Objective C class named User.
2. A popup display with "Would You like to configure an Objective-C bridging Header". Choose Create Bridging Header.
3. Go to Build Settings.4. Set Product Module Name : ProjectName
5. Set Defines Module : YES
6. Set Embedded Content Contains Swift : YES
7. Set Install Objective-C Compatibility Header : YES
8. Set Objective-C Bridging Header : SwiftInObjectiveC/SwiftInObjectiveC-Bridging-Header.h
9. Import Auto generated header "ProjectName-swift.h" in your *.m file.
10. Clean and Run your Project
|
Import into Swift |
Import into Objective-C |
Swift code |
No Import Statement |
#import |
Objective-C Code |
No Import Statement; Objective-C |
#import "Header.h" |