Xcode issue importing header file - ios

I've an iOS project, with cocoapods for external libraries management.
When I try to import an header file from that, instead of the right library, Xcode imports the file (with the same name) from another project/folder.
Furthermore the file is different.
If I want to reference to the right header I must write the absolute path
#import "Pods/CHCSVParser/CHCSVParser/CHCSVParser.h"
Why?

Related

"Non-portable path to file "File.h"; specified path differs in case from file name on disk" warning in bridging header after updating to Xcode 8.3

I updated to Xcode 8.3 and Swift 3.1 and got this warning in my bridging header file, referencing to an Objective-C header file:
Non-portable path to file "File.h"; specified path differs in case from file name on disk
How can I resolve this?
It turned out that I misspelled the file's name, the correct name was "FILE.h" instead of "File.h". The warning appeared because of the soon coming APFS to macOS.
In my case, the !!project folder name!! isn't match the bridging header path.
I changed
"project/project-Bridging-Header.h"
to
"Project/project-Bridging-Header.h"
Tested on Xcode 9.3
One additional cause, that I experienced, was that a library project was importing itself incorrectly. For example, given projects Main and Library, Main would import Library with:
#import "Library/Library.h"
If Library attempts to use the same import, the Non-portable path warning will appear. Removing the path portion is the easy fix:
#import "Library.h"
The better fix is to import the specific components that Library needs from itself:
#import "Widget.h"
#import "NSString+Library.h"
Encountered the problem in Qt (C++) on a MacOS computer from a code developed and working on Ubuntu.
My project had two files : server.cpp and Server.cpp.
The solution was to change the name of one file or the other.

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.

Xcode can't find header file

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.

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.

How to tell Xcode how to include a library specified with angle brackets?

I often see open source code importing third-party libraries in Xcode / Objective-C implementation files like this:
#import <ThirdPartyLibrary/utilities.h>
but when I drag & drop the file structure and files of such a library in my project, all these imports are corrupted and Xcode does not know where the files are.
I end up hand-modifying every import to look like:
#import "utilities.h"
And include appears it is relative to the current physical folder on the file system. When a library split its files in folders on file system and I drag-drop it in Xcode, Xcode creates groups for the folders. But for import, I have to specify the folder name. Problem is when I am in a folder, for example:
http/httpTools.h
Then when httpTools.h wants to import utilities.h from the root, I have to change
#import <ThirdPartyLibrary/utilities.h>
to
#import "../utilities.h"
which is a chore. After doing this for 5 hours I thought damn, there must be a better way. Can someone explain what is the secret to teaching Xcode a new framework location that can be imported with angle brackets? The framework btw is source code. Not compiled. Just the naked code.
Specify the include path using the compiler flag -I, or the Xcode build settings alias HEADER_SEARCH_PATHS. Of course, you can use build variables when doing so.
Just stumbled upon the same issue, there are two types of search paths in Xcode:
Header Search Paths
User Header Search Paths
If you add your own include folders into Header Search Paths, you can use angled brackets.

Resources