Issue in using swift files into my objC project - ios

I've to use some .swift file into my objctiveC project.when I'm trying to add the swift files into bundle, the productodule-swift.h file not getting generated instead its generating bridging header file.I've changed my project settings DEFINES_MODULE to YES and PRODUCT_MODULE to myprojectnameModule...but no use...is there anything I'm doing wrong.please suggest me...thanks in advance

MyProductName-Bridging-header.h,MyProductName-Swift.h both are generated when importing a .swift file for the first time.
MyProductName-Swift.h file is not visible but exists in project.Never Delete MyProductName-bridging-header.h file
Settings DEFINES_MODULE should be YES and PRODUCT_MODULE should be MyProductName.
Add # import "MyProductName-Swift.h" in your objective-c class.

Related

Unable to get correct file path from bridge header when project name has a space

I have created a manual bridging-header using these these instructions. However, my project name has a space in it. I get the following error when compiling:
Bridging header '/Word-Word/Word-Word-Bridging-Header.h' does not exist
Here is what I have put under the bridging-header section in the project's build settings:
/Word-Word/Word-Word-Bridging-Header.h
How can I get the correct file path? Thanks!
I had to leave the space in there rather than adding a dash between the 2 letters.
Is that truly the path? I would tend to think not, since it implies it is at the root directory.
Assuming you mean the Objective-C Bridging Header setting from Build Settings ... that path is relative to the file your .xcodeproj is located. So, for example if your structure looks like
Word-Word.xcodeproj
Word-Word/ (note this is a directory)
Word-Word/Word-Word-Bridging-Header.h
You would need the Objective-C Bridging Header to be Word-Word/Word-Word-Bridging-Header.h.
If your bridging header is in the same directory as your .xcodeproj, then you would need to set it to be: Word-Word-Bridging-Header.h
Since only you right now know your directory structure, you will need to determine the proper relative path to use.

How to add files to an already created bridging header?

I currently have a bridging header set up and I want to add more files to it but when I do so I get a "file not found" error:
I know the pod is set up correctly. I'm pretty sure my bridging header is set up correctly. I have it in the MyProject_Showcase-Bridging-Header.h format. It's been added to Targets - Swift Compiler Code Generation. It looks like the first item on the bridging header is working fine. I'm not sure why it can't find the 2nd one.
It looks like your syntax is incorrect. Try replicating the top import.
Something like <fileDirectory/IQDropDownTextfield.h>
Just type in the heather:
#import "file-to-import.h"

How to use swift files in objective c

I want to use my Swift files in Objective-C code. I found different link that say how to do it.
My project name is: Test-Project.
I imported #import "Test-Project-Swift.h" to my .m file to use needed classed in objective c source code.
I watched this video and there is no problem, but I have 'Test-Project-Swift.h' file not found.
As we recognized:
It looks like the problem with "-" we need to change it to "_" - "Test_Project-Swift.h". I've checked Objective-C Generated Interface Header Name in the project settings.

bridging swift and objective-c

I have objective-c project and I added swift files in it. i created bridge file and imported swift file in some header files without problems.
But I need to import some header files to swift files by adding them in the "<project-name>-Bridging-Header.h" file.
If I put header file in that bridge file and this header file was import swift file before; Xcode give me error message: "file not found" for the swift bridge file.
i.e:
I have project name called: "ProjectBlaBla"
I have header file called "readingPage.h"
I have swift file called: "readingSwift.swift"
swift bridge file's name: "ProjectBlaBla-Swift.h"
I created header bridge file: "ProjectBlaBla-Bridging-Header.h"
I imported "ProjectBlaBla-Swift.h" in "readingPage.h" file without problem and used swift classes inside objective-c
when I import "readingPage.h" in the "ProjectBlaBla-Bridging-Header.h", I got error message in "readingPage.h" said: "ProjectBlaBla-Swift.h file not found"
any suggestions ?
thanks
You are not able to reference -Swift.h files directly or indirectly in -Bridging-Header.h files.
If you open -Swift.h, you will see a line near the top, in my case line 99: #import "/Users/.../...-Bridging-Header.h", meaning -Swift.h already imports -Bridging-Header.h, so importing back creates a circular dependency.
To avoid this, any header you import in -Bridging-Header.h must use forward references to Swift classes or protocols it uses as described in answers to this question.
In short, if readingPage.h uses a Swift class named MySwiftClass you should:
Remove any references to -Swift.h from readingPage.h.
Import -Swift.h in readingPage.m
Insert #class MySwiftClass; into readingPage.h before the class is used, letting Objective-C know that such a class exists and is declared elsewhere.
Check whether the bridging header path is correct. On the left, select your project name -> TARGETS -> Build Settings -> search for Objective-C Bridging Header. Refer the photo below.
Two options
Import the "ProjectBlaBla-Swift.h" inside the "readingPage.m" file instead of "readingPage.h" file
Create a new PCH file named "Prefix.pch" and import "ProjectBlaBla-Swift.h" inside the "Prefix.pch" file.
Note: Prefix.pch is a precompiled header which makes compiling faster. You do not need to reimport any files that are imported in prefix.ch file.

How to keep the header path if using cocoapods?

I don't know how to describe this question clearly,I can't speak English very well.
I'm creating a CocoaPods Spec, I got these folders and files in my project:
MySDK/*.(h,m)
MySDK/AdvertisementSDKS/Millennial/*.(h,m)
MySDK/AdvertisementSDKS/Millennial/SDK/MillennialMedia.framework
and Podspec's source_files looks like
s.source_files = "*.{h,m}", "AdvertisementSDKS/**/*.{h,m}"
also include framework
s.vendored_frameworks = 'AdvertisementSDKS/Millennial/SDK/MillennialMedia.framework
in Millennial folder there is a .m file that imports:
#import <MillennialMedia/MMInterstitial.h>
When I try compile, Error occurs, Because compiler cant find the path of MillennialMedia/MMInterstitial.h
The correct import way is
#import <MMInterstitial.h>
Are there any settings I missed, that I can set to keep the original #include path?
Because there are lots of other same issue, I have to modify it one by one...
Thank you!
OK, I'll answer my own question:
I missed some settings of Podspec, Just simply add
spec.header_dir = './'
(The directory path depends on your project)
To your podspec, Then, It'll keep the original path works
Don't need to modify the header path! Woohoo!

Resources