I am testing myObjCClass which uses a forward declaration to get a Swift class I'm using, I did this because I was getting "failed to emit precompiled header" if I imported the Bridging Header in the .h file. In forward declaration my bridging header import (-Swift.h) is in the .m file. When I try to test this I am able to test my Swift Class but not the classes that inherit from this. I have tried adding #import "MyProject-Swift.h" in my test but I will get the error file not found.
- Obj-C.h file:
// forward declaration
#class mySwiftClass;
- Obj-C.m file:
//import bridging
#import "MyProject-Swift.h"
- Obj-C-Tests.m file:
//import that fails
#import "MyProject-Swift.h"
How can I fix this? I just want to test the Swift classes I am using in my Objective-C code.
I have already tried making a new bridging header and importing the main target one into the new test target bridging header, that will give me another "failed to emit precompiled header" I have also tried to set the test target bridging header to the main targets bridging header.
The problem is that the -Swift.h bridging header file is generated automatically into the DerivedSources directory, which is not in the header search path of other targets.
Therefore, you need to add it:
Open the the test target settings
Navigate to Build settings -> Search Paths -> Header Search Paths
Add the value $CONFIGURATION_TEMP_DIR/Your-project-name.build/DerivedSources
Now the import (and everything) should work:
Related
I added a swift class in my existing Objective-C project and was trying to import bridging header file of the form #import <ProductName/ProductModuleName-Swift.h> in some existing obj-c classes. But I got error that the header file is not found. I have put the correct Product name and Product Module Name but still I have no clue what exactly I am doing wrong. Also, I got this error: Umbrella header 'ProductName-umbrella.h' not found.
I have following lines on my Bridging-Header.h
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "FMDB.h"
#import "UAProgressView.h"
#import "ASValuePopUpView.h"
#import "ASValueTrackingSlider.h"
#import "JZMultiChoicesCircleButton.h"
#import "VYPlayIndicator.h"
#import <AVFoundation/AVFoundation.h>
It works great with no errors when I run it on the simulator.
But when I run it on the device, it highlights with error "'FMDB.h' file not found". If you remove the line "for testing purpose" the error goes to the next line and so on.
What could be the problem when I run it on the device????!!!
In Xcode, select your project target, build setting and search for 'objective-c bridging header'. make sure the path equals the path of your bridging header file
Im adding an ad network called StartApp and I messed up my bridging header in my build settings in xcode swift. I get an error saying this. Why is this happening?
<unknown>:0: error: bridging header '/Users/welch/Desktop/DONT DELETE/My Project/My_Project/My_Project-Bridging-Header.h' does not exist
From the build settings of your your app target find section Swift Compiler - Code Generation and delete the Objective-C Bridging Header or replace it with your new header filename.
If your following the steps of naming your bridging header (Projectname-Bridging-Header.h->spaces replaced by '-') , then You have to make sure , pointing to the right Path of you bridging-header file in Target->Buildsettings->Objective-c bridging header ,,I mean make sure to include parent directories if any!
I created a protocol
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
// Defines the protocol that must be implemented to be a delegate for UCMapviewController
#protocol UCMapviewDelegate <NSObject>
#required
- (void)pushMapviewRight;
#end
When I go to new file -> protocol, there is a prompt which asks for the target. I check my project. But when i click the protocol.h file in my project and look at file inspector, at "Target membership", my project is unchecked and I cannot check it.
I don't get this error when I put the protocol in the header file of one of my viewControllers (for example). Do I have to import the protocol somewhere else?
WHat is wrong? Help is greatly appreciated! thx
Header files don't go into a target, unless you're building a framework and want to copy the header file into the Headers folder in the framework. When building an app, only source files belong to the target.
You'll notice that if you select one of your other headers in your project, it will also not be in the target. Only the corresponding source file will be. This won't matter. If the header is in your project, you can #import it just fine.
I have downloaded the Dropbox API for Objective-C/iOS devices, and I am able to successfully build and run the DBRoulette application.
When I follow the README directions for including the API in my project, I have an enormous number of build errors, all appearing to be related to missing the Foundation header. (Eg. Can't find the interface declaration for NSObject, NSString, etc.)
Many of their header files don't include any other headers at all. Don't all .h files need to import Foundation.h if they extend NSObject? This doesn't seem to be the case, as the example project (DBRoulette) builds and runs fine without the Foundation header declarations, but my own application fails miserably.
I must be missing some sort of project setting, but I can't determine what it is.
Screenshot of One Failing Class
In their example app, they have
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif
in their prefix header file (DBRoulette_Prefix.pch). This file is automatically prefixed to all source files in the project, so the appropriate headers are found. You can either put the #import directives in the source files themselves, or do what they did and edit the .pch file for your project.