Xcode can't find header file - ios

I am trying to make a framework for my project. Into my framework I added the path of my header files to target>Build Settings>header-search path. After that I added this framework to my project by Build Phases>Link Binary With Libraries.
When I want to import the header file which I included in my framework, I get a .h file not found error. Is what I'm trying to do possible? Or am I missing anything?
I created framework like that;
Opened new project as iOS>Framework&Library>Cocoa Touch Framework
I didn't add any class, i just added header search path and library search path and linker flags. I don't think i did a mistake in this part because we do it in every project but first time i m doing this for framework. Then i pressed run and get my framework from Products.
I opened my project and added framework Build Phases>Link Binary With Libraries. I m able to import header file of framework like #import <myframework/framework.h>
After this i added framework also General>Embedded Binaries. Everything look normal but i cannot add headers to my project which i included to my framework with header search path. I have to use header search path because there is tons of headers, i cannot add all of them to my Xcode.

Make sure you all Public Header appears in Public Section else drag and drop .h file to public

Everything look normal but i cannot add headers to my project which i included to my framework with header search path.
It sounds as though you're expecting all the headers that can be found at the path specified by your header search path will become part of your framework, so that if there's a header named SomeHeader.h in your search path, it will be built into your framework and you'll be able to import it into client projects like:
#import <MyFramework/SomeHeader.h>
But that's not the case at all. If you want your framework to provide SomeHeader.h, you need to add that file to the project and, as Meghs Dhameliya already pointed out, you need to specify SomeHeader.h in the Public Headers portion of the Headers build phase. This will make Xcode copy the header file into the framework so that clients of the framework can import the header file. It's not clear that that's what you really want, though... in comments you wrote:
There is a lot of headers in another path. I have to use header search path unfortunately. Kind of company rule.
So it sounds like all projects in your company specify the same header search path so that they have access to these header files. If that's true, then there's no reason for projects to need to #import them from your framework, but in that case it's not clear what the actual problem is. Or, perhaps you're creating the framework so that client projects can get the headers from your framework instead of having to reference the header search path. In that case, you will need to add those headers to the project and specify them as described above.

Related

Include of non-modular header inside framework error

I realize this is a common error and has been asked several times but I am unable to resolve it after trying several different things based on others' answers.
I am creating a framework project (Obj-c) which uses another third-party framework. In MyFramework's umbrella header, I have the import statement of third-party framework. When I packaged my framework and included it in another iOS project, it fails to build with this error.
Things I tried:
Turned ON "Allow non-modular includes in Framework modules"
Added the umbrella header of the third-party framework as a "Public" header
Please advise what is missing here. Thanks in advance!
Here's the Exact Error:
Include of non-modular header inside framework module
'MyFramework.TestManager':
'/TestApp/WindowsAzureMessaging.framework/Headers/WindowsAzureMessaging.h'
Also, from the path it looks like it is trying to search for it in the TestApp project, whereas it should refer from the Framework.
I imported the Azure Messaging Framework in the Umbrella header as shown below:
#import <WindowsAzureMessaging/WindowsAzureMessaging.h>
I was able to reproduce your error. I looks like the WindowsAzureMessaging header and all other headers it refers are not made to be used in a modular framework umbrella header, because it uses "user" imports instead of "system" imports relative to the framework, and also it doesn't have the modulemap file.
You have several options:
adapt their code and make it build as a module (make it "modular").
not include it in the umbrella header (avoid referencing things from it there), but link it and use directly in the app and your framework.
instead of using the file framework as a separate entity, you could take (copy) their source code (m and h files) and compile into your framework, and then expose some headers as your own headers.
I think that option 1 is the right way to go. It is not hard, and if you manage to do that, think about making a pull request for their repo, because this is going to benefit everyone.

Unable to import bridging header

Im trying to link an external Objective-C framework, "frameworkSDK", to my swift project. However I seem to be getting this error :
<unknown>:0: error: failed to import bridging header
I've looked at loads of solutions to my problem but non of them seem to work. Here's what I've done so far :
I've created a "bridingfile.h" at the root of the project and
imported "frameworkSDK.frameworkSDK.h" to the file.
I've made sure Objective-C Bridging Header path was correct under
Swift Compiler - Code Generation.
I've changed my framework search paths to the where the
"frameworkSDK" is located - Code Generation.
Added the path to "bridgingfile.h" to Header Search Paths - Code
Generation.
I've tried to instead create the bridgingfile 1 directory in from
the root folder, and then update accordingly.
Any help would be greatly appreciated! :)
If you are importing an external Objective-C framework, i.e. one stored in, say, frameworkSDK.framework directory structure (bundle), you should not have to worry about a bridging header. Instead do the following:
Under Build Settings set Framework Search Paths to the parent
directory of the frameworkSDK.framework directory.
Also under Build Settings set Runpath Search Paths to
$(FRAMEWORK_SEARCH_PATHS) #executable_path/../Frameworks.
In a Swift file where you want to use the Objective-C framework do
import frameworkSDK.

Importing a library in to an Xcode 7 project

So I am trying to add a static library to my project in order to interface with a scanner. I have linked the binary in build phases to the libCaptuvoSDK.a, put the Captuvo.h header file in the project folder, and finally set the project to always search the user paths and added $(BUILT_PRODUCTS_DIR) recursive to the user header search paths. After doing all this I am trying to use #import "Captuvo.h" in my ViewController.swift file and getting the 2 errors Expected identifier in import declaration, and Expected expression. I have tried different combinations of importing and none of them seem to make a difference so I am led to believe the issue is with my process of adding the library.
I am new to Xcode and have never used a third party library in an application before so I feel I may be making a simple mistake or just misinterpreting things. Any help is appreciated!
Okay so I managed to fix my issue! I had imported the static library properly but the real issue was the header file. I fixed my issue by creating a new file in my projects folder named Quick-Scan-Bridging-Header.h. Inside that file is where the #import "Captuvo.h" line belonged. Once that was done I opened the Quick Scan apps build settings and under Objective-C Bridging Header I added the path Quick Scan/Quick-Scan-Bridging-Header. I also added the Header Search Path $(BUILT_PRODUCTS_DIR)
After I did all this I am able to use the Captuvo classes in my ViewController.swift file.

Can't include Objective C Files into Project?

I want to include an Objective-C project (https://github.com/soffes/ssziparchive) into my Swift Project so that I can include the SSZipArchive into my project. I need this so I can unzip a file. As included in the instructions on the Github, I included the folder minizip, SSZipArchive.h, and SSZipArchive.m into my project. I have also created a bridging header where I included the following import into my project #import "SSZipArchive.h". However, when I try to type SSZipArchive on Xcode, the autocomplete doesn't occur, leading me to believe that SSZipArchive isn't included properly in my project. Any ideas on how to do so? I have already looked at numerous links on how to include Objective-C projects into Swift and I have found that I simply need to include the corresponding header files for my project to work.
I guess that you haven't set bridging header path properly. It's a very common problem, but easy one to fix.
Go to the Project Settings -> Build Settings -> Search, and search for bridg, and under Objective-C Bridging Header set the path of your bridging header file (carefully inspect it's path in Finder first, since it may be in some sub-directory of your project).
Also make sure that all your included header files have target of your application. To check if they have, click on the header file, open up Utilities from the right side and under Target Membership, make sure the first target is checked.

Linking one xcode project from another

I have two xcode project for example A and B. I include project B into A and try to import some header files of project B. Project B is built successfully but when I try to build project A It throws error as header file not found. How can I resolve this?
In Xcode, for Project A check your build settings->Header Search Paths and User Header Search Paths. Do they contain the path of the header files for Project B? If not, add the path in one of these fields.
Watch out:
Including a header in a Header Search Path involves writing this:
#import <header.h>
whereas importing a header in a User Header Search Path involves this:
#import "header.h"
I would recommend putting it in the Header Search paths to distinguish including headers from project A and project B in your code. It improves readability in my opinion.

Resources