How to add files to an already created bridging header? - ios

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"

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 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!

Expected identifier for every occurance of "(Class)class" in LARSAdController

I'm currently trying to add LARSAdController to my iOS project with no success.
As soon as i import the files via #import "LARSAdController.h" in my AppDelegate.h the build process fails and on every occurance of (Class)class in LARSAdController.h i get the cryptic error "Expected identifier". BTW I'm using cocoapods.
Example:
- (void)registerAdClass:(Class)class;
which seems fine to me...
If i create a blank project and import the files they compile, so the problem must be in some relation to my code. Anyone got an idea what may cause this?
Thanks for any help in advance!
class is a reserved word in C++, so I would imagine that some of your project uses Objective-C++.
To solve this, use #import LARSAdController.h in Objective-C implementation files only, and remove its use from header files. You can use #class to forward-declare any occurrences of whatever classes are defined in LARSAdController.h in header files (this is best-practise anyway).
If you need to use LARSAdController from an Objective-C++ class then this is more complicated and you will need to use an Objective-C proxy object or modify their header files (which isn't ideal).

Resources