Xcode 7 can't find header files from framework - ios

I'm trying to add PassSlot into my project, but it says it can't find the .h file. I'm following everything correctly from here: https://github.com/passslot/passslot-ios-sdk
Is this an Xcode 7 problem? It was working fine and now that I opened the project in Xcode 7, it is giving me this problem. I reopened it on Xcode 6 and it starts showing the problem as well.

I think Dinesy is right. This solves the problem for me.
I've noticed that Xcode7 doesn't automatically fill in the required
Framework search paths when you import a 3rd party one (I believe
Xcode6 did do this). Check if yours are empty by going to Project ->
Build Settings -> Search Paths -> Framework Search Paths. Fill it in
with wherever your Frameworks live. If it's under your project you can
use $(PROJECT_DIR)

Replacing #import "Headerfile.h" with #import <Framework/Headerfile.h> worked for me.

When you Drag & Drop the required framework to your Frameworks folder, Tick on "Destination: Copy items if needed"
Then you would be able to reference it properly now.
Screenshot

Just ran into this with Xcode 7 and I ended up having to copy the 3rd party Framework (and bundle) file into my project's main directory before dragging it into the Xcode project. This allowed it to add the correct Framework search path and no longer gave me any problems.

Just hit this problem myself after making a new test target in Objective-C.
One thing to remember is that under some circumstances, each test target must be listed in the Podfile with pod dependencies. If the Podfile only associates the project with the pods, it may not find the pod header files.
Here's an example of a more complex Podfile from the cocoapods docs.
target 'MyApp' do
pod 'ObjectiveSugar', '~> 0.5'
target "MyAppTests" do
inherit! :search_paths
pod 'OCMock', '~> 2.0.1'
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
puts "#{target.name}"
end
end

I ran into this error when trying to link to my own custom framework. The problem was that I hadn't set up my framework to export the needed headers. To do so:
Select each header file you want to make available, go to the File Inspector > Target Membership, and make sure the target is checked and set to "Public".
In the MyFrameworkName.h top-level file, import each header file you want to make available: e.g. #import <MyFrameworkName/MyPublicHeader.h>

In my case, using CocoaPods, Xcode was building fine, but a command line build couldn't locate the framework headers.
The solution was to build the workspace, not the project!

Cleaning the project and restarting XCode sometimes helps

Related

Xcode 7.3 Syntax Highlighting and Code Completion issues with Swift

I am having an extremely frustrating issue with XCode 7.3 (however, this issue has persisted since I installed XCode 7.2) and Swift code, and I am hoping others have had this issue and know how to resolve it. Syntax highlighting and code completion work perfectly fine in Objective-C files, and also works fine when calling other Swift objects within Swift code. However, any Objective-C objects or methods mentioned in Swift code get no syntax highlighting, and XCode will not complete ANY Objective-C declared methods or properties. Everything compiles and runs just fine.
I should also add that I have also tried doing a completely clean install of XCode. I deleted all my derived data, deleted all XCode caches, and deleted my XCode preferences files (in addition to obviously deleting the XCode.app archive before re-installing).
It is making it extremely difficult to develop in Swift. I don't want to do this, but if I can't find a way to resolve this I'll be forced to go back to using Objective-C.
I have the same problem. But finally solved it.
I make two change, not sure which is the key point but you can try them all.
delete the module cache
Within the same folder as your project's Derived Data is a Module
Cache. When Code Completion stopped working, deleting this fixed it.
Close Xcode and delete the
~/Library/Developer/Xcode/DerivedData/ModuleCache directory.
change the Enable Modules value
Go to the Build Settings of your target, then search Enable
Modules
If it's Yes, change it to No, and you may get some build
error, just change it back to Yes.
After two steps above you should Clean(Shift+Command+K) your project.
For now you may fixed the problem.
So it seems the issue was with CocoaPods. I was using Cocoapods as a static library instead of as frameworks. Switching to frameworks (using use_frameworks! in my Podfile) and importing the libraries into Swift has resolved all my issues. I'm guessing all those third party library headers were just too much for XCode to process. Either way, the issue is now resolved. I hope this helps someone in the future.
This might not be necessary anymore but i still want to post this:
At the time of this post, the most recent version of cocoapods (1.0.0.beta.8) requires you to define pods for each Xcode target.
In my case I had a class compile for the project target and for a testing target. I added a pod only to the main target, because of laziness.
Now working in the code of class A I added the pod framework using import NAME and tried to use the classes of the framework. Xcode wouldn't highlight the particular code where I use the new classes, but compiling and running works fine. In the completion dialog the type of the variable was <<error type>>
The way to resolve this issue: in the Podfile add the newly added pod to all targets, the class A is member of.
Now Xcode finds the necessary frameworks for all targets and code highlighting works again.
EDIT 1:
A possible solution is defining a list of shared pods, like in my example:
platform :ios, '8.4'
use_frameworks!
inhibit_all_warnings!
def all_pods
pod 'MPMessagePack'
pod 'SwiftyDispatch'
pod 'BFKit'
pod 'Timepiece'
pod 'Alamofire'
pod 'AlamofireSwiftyJSON'
end
def testing_pods
pod 'Quick'
pod 'Nimble'
end
target 'App' do
all_pods
end
target 'AppLogicTests' do
all_pods
testing_pods
end
target 'AppUITests' do
pod 'RxTest'
all_pods
testing_pods
end
post_install do |installer|
installer.pods_project.targets.each do |target|
puts target.name
end
end
This will add all pods to all targets and adding all testing pods to the targets. Next to these I added 'RxTest' to the AppUITests.
(Chosen pods are examples of my projects, no advertising intended :-) )
We had the same issue in a mixed ObjC/Swift project. Tried all the suggestions about deleting derived data etc, to no avail. Sometimes it helped, but not in a reproducible way and after some time it stopped working.
The post of Galvin in this post put me on the track of the Module related build settings. However it was another setting that solved the code completion/coloring in a reproducible way: setting DEFINES_MODULE (under Packaging) from YES to NO for our main project was the solution.
Notes:
I expected this to break the ObjC/Swift interoperability in our project, but that still works. It seems that setting is only to be used for framework targets. (https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html)
This project setting has not been changed for months, but the code completion issues came up only recently, both for my colleague and me.
If none of the above worked for you and you're using Cocoapods, you can try switching to Carthage.
I tried every suggestion I could find on Google to no avail. But consistently Cocoapods seemed to be coming up as a reason with many hacks in attempt to fix it. I have been reading up on Carthage, and how it doesn't modify your project, force you to use a workspace, or potentially fill your build folder with header files (which confuses Xcode and can cause the syntax highlighting and autocomplete to break).
After making the switch I haven't run into any issues yet, and to be honest I prefer the teensy bit of overhead to have a clean solution. This post really drove it home for me.

xCode 7 error: include of non-modular header inside framework module with Google Maps

I updated to xCode 7.1 today and tried to build my app but I'm getting this error:
I have already tried going to Build Settings under "Target" and set "Allow Non-modular Includes in Framework Modules" to YES but that didn't solve this issue.
UPDATE: Since this was preventing me from compiling and hindering my progress in terms of development, I recommend you download an older version of xCode from Apple (https://developer.apple.com/downloads/ make sure to login). You can download version 7.0.1 from the link and at least continue development.
This is what I've done and I can continue development.
I know this is not a fix, but its workaround for the people who wish to continue development.
Google has updated its SDK to 1.10.5, Just Reinstall Pod and it should work fine. I was facing same issue and now all issues are fixed after pod reinstallation.
I ended up having to create an Objective-C bridging header file and adding #import <GoogleMaps/GoogleMaps.h> whereas I hadn't needed one previously since I was using Cocoapods in a Swift project and the use_frameworks! setting had previously taken care of this.
Here's instructions for how to create the Objective-C bridging header file: (https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html)
https://forums.developer.apple.com/thread/23554
Just remove the header search paths in build settings. In new Xcode versions (after 7.0 I guess) you need to look for the headers by linking frameworks and not by linking header files directly.
For me, this issue was resolved by:
Product > Clean (cmd k)
Product > Clean Build Folder (cmd opt k)
Product > Run (cmd r)
This thread may be useful.
I tried a few things, but I'm not positive which one fixed the issues.
First, I edited my Podfile to include:
post_install do |installer|
installer.pods_project.build_configuration_list.build_configurations.each do |configuration|
configuration.build_settings['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
end
end
Then, I added a bridging header file, with one line:
#import <GoogleMaps/GoogleMaps.h>
Cleaned and rebuilt the project and that did the trick.

How to get cocoa pods to work?

I have installed cocoapods. I've done everything that I've seen online, yet I can never successfully import a 3rd party framework into my project. I have tried many, many times--at least 20 probably, and have not once been able to successfully do this. Take for example, this library: https://github.com/uacaps/PageMenu
I added the podfile, I ran "pod install", that worked, I opened up the workspace and not the original project, I added the framework under "linked frameworks and libraries." But it still says "No such module Page Menu." It does this for every single pod that I try to install. What am I doing wrong? From what I've read everyone seems to think they are so easy to install. And they are, problem is they just never work once I do install them. Is there some missing step that everyone else knows about that I don't? I have looked under build settings and I've read something about changing the linker flags, but I couldn't figure out how to do that. I have tried installing the library manually and that didn't work either. Could it be that something is just wrong with my Xcode? I've been having this problem for a few months, and it has stayed consistent since I updated my Xcode recently. Does anyone have any idea what this could be?
edit: link to Podfile photo:
http://i58.tinypic.com/2lc2zqb.png
First,make sure that you have something like this in your PodFile (same folder as your xcode proj)
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'PageMenu'
then cd to the directory and do pod install in terminal.
I am assuming that you are using swift. Build the project. Go to your report navigator.
EDIT:: Do open the proj using xcworkspace instead of xcodeproj
You should see something like this.
This tells you what you have to add in your bridging header.
To create a bridging header, create a random objective c file (with cocoa touch class). XCode will ask you if you want to create bridging header.
Select yes, then delete the files you just created. Next, go to the generated bridging header file. Add in
// this header should be based on the name you see in report navigator.
#import <PageMenu/PageMenu-Swift.h>
Look, Calm Down..
I had the same problem.Didnt give up.try doing this as well,worked for me
create new project
close xcode
go to target folder pop init
open -a Xcode Podfile-uncomment platform -pod 'PageMenu' ( I typed this outside target this time/not like the usual way typing it inside target- do/ ,save and close)
open xcodeworkspace and Type - import PageMenu -( still says unresolved module )
Now Build ..
(worked for me, It somehow works with clean or Build i suppose ,so try both)

"No such module 'Alamofire'" won't recognize framework

I am trying to add Alamofire to a new XCode project with Swift. I feel like I have tried everything.
Every time I try to add
import Alamofire
I get "No such module".
I have tried installing it as stated on https://github.com/Alamofire/Alamofire,
I tried doing it manually first, then Carthage and Cocoapods, but with the same result.
I have tried deleting the DerivedData folder and rebuilding the project without any luck.
It is a completely clean install, yet it just won't recognize the framework. I have tried the suggestions in the first 10 Google searches and here on Stackoverflow (Cannot install Alamofire in new Xcode Project. "No Such module Alamofire") Here are some screenshots from my latest manual attemp:
Looks like you are using the module by directly dropping the source files into your project.
If that's the case, you don't have to use import Alamofire header or use Alamofire( dot ) in the beginning of every method.
Just use the code as below omitting Alamofire tag.
request(.GET, "https://httpbin.org/get")
I know it's late answer, but I was facing same problem with Xcode 8 Swift 3.0. I follow this Alamofire link and added framework manually. Its working fine. One of my project stuck on 'no such module' error, I cleaned derived data (Cleaning derived data removed source files of Alamofire. I added it again in my project ;) ) and it works like charm :).
Followed instructions
Download Alamofire
Drag Alamofire project in your project directory
Check alamofire deployment target same as your project
Go to your project general settings, click on the + button under the "Embedded Binaries" section.
You will see two different Alamofire.xcodeproj folders each with two different versions of the Alamofire.framework nested inside a Products folder. It does not matter which Products folder you choose from, but it does matter whether you choose the top or bottom Alamofire.framework.
Select the top Alamofire.framework for iOS and the bottom one for OS X.
And that's it! The Alamofire.framework is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.
same error here.
I solved the problem by the following steps:
Click on your project (targets)
Click on Build Settings
Under Search Paths-Framework Search Paths, add the directory path which contains Alamofire.framework
Hope this can solve your problem!
I was importing Alamofire and I ran into the same issue. Turns out the Cartfile was not in the same folder as the .xcodeproj file.
Once I moved the Cartfile, the Cartfile.resolved files and the Carthage folder to the same folder as the .xcodeproj file my project didn't trigger any errors.
Make sure to also add this line to Build Settings > Framework Search Paths:
$(PROJECT_DIR)/Carthage/Build/iOS
I was able to resolve this issue changing my Podfile. I originally had the reference to Alamofire in a target:
The problem disappeared when I changed the podfile to the following:
platform :ios, '8.0'
use_frameworks!
pod 'Alamofire', '~> 3.0'
pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git'
target 'xxxxxxx' do
pod 'GoogleMaps'
end
target 'xxxxxxxTests' do
pod 'GoogleMaps'
end

XCode keeps forgetting imported Frameworks

I have Xcode 6.3, using Swift, importing a Parse 1.7.1 Framework as usual (dragging, copying) and I set it up in a group: Frameworks.
I compile and everything works fine for a while with it, until the compiler does not recognize this sentence anymore:
import Parse
It gives me the error:
No such module 'Parse'
A workaround is to delete the Framework and copy it again, but after a while it starts getting annoying, and I would really like to know the cause.
I only code and build in the meantime (and occasionally creating new swift files), so I can't explain why this happens.
If you're targeting iOS 8 and above, you can tell Cocoapods to use frameworks, by putting
use_frameworks!
in your Podfile, like this example:
use_frameworks!
platform :ios, '8.0'
# Parse
pod 'Parse', '~> 1.7'
I could fix the same problem by doing so.
I just fixed this same issue today with my project. I imported my obj-c framework in a swift project and it worked for a while, then xcode seemed to forget it causing the same error you have.
apple docs
I fixed it by referencing the bridging header in Build Settings.
Under Build Settings, make sure the Objective-C Bridging Header build
setting under Swift Compiler - Code Generation has a path to the
header. The path should be relative to your project, similar to the
way your Info.plist path is specified in Build Settings. In most
cases, you should not need to modify this setting.
I just typed in the name of the bridging header folderName/xxxx-BridgingHeader.h in the field that states bridging header and all was well again.

Resources