Can't import newly added framework file - objective-c

I have an existing framework (MyFramework) and I've added a new class to it, NewClass. In another project I am already using this framework and I now want to use NewClass as well. I use the following import statements:
#import <MyFramework/OldClass.h>
#import <MyFramework/NewClass.h>
When I compile the project, I get an error on the second import that says "MyFramework/NewClass.h: No such file or directory". NewClass.h is in the exact same location as OldClass.h, the framework compiles with no errors, I've made sure to clean out any old artifacts, and I've verified that in the framework's target I've included NewClass.h in the "Copy Headers" build phase.
What additional step is required to make a framework's header files available to users of the framework?
p.s. I realize that I should likely have a single MyFramework.h for anyone wanting to use the framework, but I'll tackle that once I've figured out how to add new headers!

Set role of the header to Public.
In Xcode 3 right click on the header, select Set Role from the menu.
In Xcode 4 select your target, open Build Phases and change the section of your header in the Copy Headers section from Project to Public.
Update:
In Xcode 4.5 select the header, open the File Inspector in the Utilities panel on the right, change the role to Public in the Target Membership section.

Related

Adding Swift Class to Objective-C Project with Multiple Targets

I have an existing Obj-C project that houses many targets that all share the same AppDelegate. I want to bridge a swift class that is used by select targets. I can do this easily when I have one target.
When I add a swift file to the project, I select the desired targets and the necessary bridging-header.h files are generated, but when I try to import those -swift.h files, they are can't be found.
Are there steps I'm missing when it comes to projects that have multiple build targets?
EDIT - More Details
I wanted to add a little bit more detail on how my project is set up.
I have a Framework, we'll call it AppFactory, coded in Obj-C. I have multiple build targets that generate different versions of the Core app depending on information in that target's plist. I want a swift file to be utilized by these apps. In my build settings the Defines Module is marked to Yes, I have create this swift class:
#objec class SwiftClass: NSObject { }
And in doing that, Xcode generated the proper Briding-Header.h files.
According to Apple Guides when you have multiple build targets your import header should include the ProductName/ProductModuleName-Swift.h, which should be auto generated by Xcode.
When I look in to my derived data folder, the ProductModuleName-Swift.h does exist, with in each targets build folder, under the AppFactoryCore folder.
I found a solution to my problem.
Swift File Targets:
Instead of having SwiftClass.swift target both the framework and the selected targets (AppA, AppB & AppC), I backpedaled and solely targeted the framework, AppFactoryCore.
Build Settings (Packaging > Defines Module):
I reverted each app target's Defines Module property from YES to NO, and set this property to YES for the framework target.
Swift Class Declaration:
The guide states:
Because the generated header for a framework target is part of the framework’s public interface, only declarations marked with the public or open modifier appear in the generated header for a framework target.
So I added access control modifiers to my class and class functions
#objc open class SwiftClass: NSObject {
//Code
}
Import Header:
Since SwiftClass.swift is only targeting the framework target, and it is in fact a framework that is being used, the header import SwiftClass.swift into the universal AppDelegate was
#import <AppFactoryCore/AppFactoryCore-Swift.h>
Which finally became visible once all previously stated modifications were done.
Now that the file is global to all targets I added a custom attribute to identify if the target running was is one that should utilize SwiftClass.swift.
Hope this helps anyone else trying to accomplish a relatively similar task!

How to import obj c framework into swift bridging header?

I always find problem when importing framework headers into my project. For example, my little trial project on this screenshot. What did I do wrong when importing Facebook SDK headers? This is a very simple step and yet I can't find out what's wrong with it. I even follow the step by step closely like on the Facebook Developers site.
EDIT: sorry, maybe I wasn't clear. The bridging header has been set and I've set the bridging header location path on the build settings. That's why it produces error, because it's included in the compilation. The problem is that with the current setup of importing Facebook SDK and bridging header, I can't import the Facebook SDK into the bridging header.
Things I've tried:
#import "FBSDKCoreKit/FBSDKCoreKit.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import "FBSDKCoreKit.h"
#import <FBSDKCoreKit.h>
#import "FBSDKCoreKit.framework/FBSDKCoreKit.h"
#import <FBSDKCoreKit.framework/FBSDKCoreKit.h>
None of them works (all of them produces error like on the screenshot, means that the bridging-header is fine and included in the compilation, but it can't find the header I refer to).
Make a Obj C Bridging:File -> New -> Source -> Header File -> Name as AppName-Bridging-Header.
Add the following (ex. in case of SDWebImage):
#ifndef AppName_AppName_Bridging_Header_h
#define AppName_AppName_Bridging_Header_h
#import <SDWebImage/UIImageView+WebCache.h>
#import "UIImageView+WebCache.h"
#endif
or
#import "UIImageView+WebCache.h"
Note: Build Settings, in Swift Compiler - Code Generation, make sure the Objective-C Bridging Header build setting under has a path to the bridging header file. - its like testSD/testSD-Bridging-Header.h or testSD-Bridging-Header.h (Open the Project folder and find the header file path)
#Chen : In your case, try Adding the “-ObjC” Linker Flag.
Select the project file from the project navigator on the far left side of the window.
Select the target for where you want to add the linker flag.
Select the “Build Settings” tab.Choose “All” to show all Build Settings.
Scroll down to the “Linking” section, and double-click to the right of where it says “Other Linking Flags”.
A box will appear, Click on the “+” button to add a new linker flag.
Type “-ObjC” (no quotes) and press enter.
New File -> iOS Source -> Objective-C File -> Enter whatever (Example "abc") name -> Next, Create -> Will show message on the top, choose Create Bridging Header -> Delete abc.h -> Click ProjectName-Bridging-Header.h -> import -> finish.
Now I've found the answer. The problem is that the framework doesn't stored inside the project folder but in download folder. And yeah, Facebook dev guide told me to drag the framework straight from where the framework is downloaded, and I didn't check the 'copy files if needed' checkbox when importing. From this answer, I found out that I need to fill in search path to the framework base folder in order for Xcode to be able to find it. Thanks for everyone for answering.

Xcode 4 'QuartzCore/CIColor.h' file not found

I'm running Xcode 4 and trying to follow the steps in Apple's Image Kit Programming Guide (which is written for Xcode 3) on how to work with an Image View and the IKImageView class. I just imported the Quartz and Quartz Core frameworks (from /System/Frameworks directory) to my blank Cocoa Application project using File > Add Files to... menu, but when I try to Run my application I get this error:
Lexical or Preprocessor Issue 'QuartzCore/CIColor.h' file not found
Does anyone know what could be a reason?
Peter Hosey replied:
You're not supposed to import specific headers directly, and especially not from sub-frameworks (such as Core Image, sub-framework of QuartzCore). Only import a framework's overall header, which usually has the same name as the framework.
I didn't import any specific headers directly, I just choose File>Add Files to... then choose /system/Frameworks and choose two folders which contain those frameworks, after that they appeared in my project navigator view as they should, but the code wouldn't compile any more. It shows me NSColor.h file which is found in the AppKit framework, points at this line: #import and says Lexical or Preprocessor Issue 'QuartzCore/CIColor.h' file not found. I have no clue why it wouldn't compile. CI stands for Core Image. I'm now reading a guide on Core Image, maybe this will help. I'd like to post a screenshot but I can't (not enough rights yet).
I just imported the Quartz and Quartz Core frameworks (from /System/Frameworks directory) to my blank Cocoa Application project using File > Add Files to... menu, …
That's not importing; that's just adding it to the project (and hopefully the target). Importing is what you do with the #import directive.
… but when I try to Run my application I get this error: Lexical or Preprocessor Issue 'QuartzCore/CIColor.h' file not found
You're not supposed to import specific headers directly, and especially not from sub-frameworks (such as Core Image, sub-framework of QuartzCore). Only import a framework's overall header, which usually has the same name as the framework.
The problem was that the Guide I used was written for Xcode 3 so when I tried to import/add some frameworks to my project using "File>Add files" menu as described, it did add those frameworks and I could see them in the project navigator, but something went wrong. In Xcode 4 you should use a different way to add/import Frameworks by using the Project Editor> Summary tab> Linked Frameworks and Libraries> Click "+" and then choose the Frameworks you need. That fixed the issue.

import "cocos2d.h" works in some files, but not all

Here is what I did:
In Xcode 4.3.1
File -> New -> Project -> Single view application
Dragged the file cocos2d-ios.xcodeproj into navigator.
In build phases settings : Added : libcocos2d.a (becomes highlighted in red), as a linked library (required).
Added OpenGles.framework, Quartzcore, and libz.dylib
Changed build settings - Set "Always Search User Paths" to YES
Added cocos2d source directory to "User Header Search Paths"
Now, it seems I can type: import "cocos2d.h" , in the app delegate and root view controller that Xcode created. But if I create a new file, and I add the line "import "cocos2d.h"" to the top, Xcode complains that the file is not found. But it seems to build fine. Also, in this new file code sense does not work.
What should I do? Why can I import only in the files that Xcode created? Is there some setting I need to change so that in the files I create, I can import cocos2d ?
EDIT: It seems to build and run fine. I can call methods in the cocos2d api. code sense just doesn't seem to see cocos2d.h in the new files I create.
EDIT - it seems that code sense suggests cocos2d.h when i type : import "
But it does not suggest classes / methods from the cocos2d api.
Turns out I had only added the "user header search paths" to my target, but not in the project settings.
Adding it fixed the problem. I guess the reason it compiled fine was because I had added it to the target, but it didn't work in the text editor since I hadn't added it to the project.
This happened to me as well, even though I did add it to both project and target.
However, what worked for me was to select the RECURSIVE checkbox under "User Header Search Prefixes" (which was set to "/lib/**")
I had same issue.
My project -> Build Settings
Look for the entry for Search Paths
Always Search User Paths - YES
User Header Search paths - "myProjectName/libs" //I put box2d folder here
Hope this help someone.

xCode 4 import Framework doesn't work

I have added the objection Framework to my project via linked binaries.
Now I am trying to import a file form this framework
#import <Objection/Objection.h>
But the compiler says: Objection/Objection.h not found!
I tried everything,
other linker flags are set to -ObjC and -all_load
Framework search Paths are set to the correct directory
The Library is linked within the project
So what else could be the problem?
Thanks for your help in advance!
When the Objection framework is built for iOS the framework is called 'Objection-iOS.framework'. Ergo the import would look something like this:
#import <Objection-iOS/Objection.h>
Did you add your framework like so ?
In the project navigator, select
your project
Select your target
Select the 'Build Phases' tab
Open 'Link Binaries With Libraries'
expander
Click the '+' button
Select your framework
(optional) Drag and drop the added
framework to the 'Frameworks' group
See Apple's documentation on this
If you have done exactly what I said above then I'm not sure if this is going to work, but I use another method to add frameworks, which is go to your project (The one with the xcodeproj icon), then click on your target. There, you can add the frameworks you want.
If that doesn't work, then try go to /Library/Frameworks to see if your framework you want is still there. If it's there and it's still getting that error, try manually adding the framework which is the add other button when you add a framework.