AFNetworking files cannot be found - ios

I have a project that is a couple years old, it uses Pods to utilize AFNetworking 1.3.3 (it was using RestKit, but I changed over to AFNetworking and still am having the same issues).
My import statements cause a compile failure
#import <AFNetworking/AFNetworking.h> // fail
#import <AFNetworking/AFHTTPClient.h> // fail
The error is simply:
Error:(23, 9) 'AFNetworking/AFNetworking.h' file not found
(or AFNetworking/AFHTTPClient.h if I try to import that one)
I can open the Pods folder in the project and clearly see the files there. I can even drill down into the classes, and my AppCode IDE auto-fills them in and/or auto imports them. But the project simply won't compile, as it does not recognize the imports above. See for reference, the files are there:
I've tried changing around versions of the framework with no luck. Any thoughts on something I may be overlooking? This project used to compile fine under older versions of Xcode, and nothing has changed with regards to the framework being used or the code using it.
Here is what my "Other C Flags" in build settings looks like with regards to what Pods setup:
Thank you in advance! Please let me know if there is more info I can provide.

It appears your IDE's list of include paths to search doesn't contain the directory of your AFNetworking headers.
Adding /Users/$USER/Desktop/blah/Pods to the list of "Other C Flags", much like in this answer for XCode, should solve your problem.

Related

Example-Swift.h not found

I'm developing an iOS framework that mixes Objective C and Swift code. Build fails at the #import "Example-Swift.h" line with 'Example-Swift.h' file not found.
The header file does get generated, I can find it at:
DerivedData/Example/Build/Products/Debug-iphonesimulator/Example.framework/Headers/Example-Swift.h
I tried all of the upvoted solutions on Stack Overflow, none worked. The only fix is manually adding the directory to User Header Search Paths in build settings.
I must be doing something wrong though if other people don't have to manually add the header path. Also, when users of this framework include it as a pod, they need to do update the build settings as well, which I really want to avoid.
So, is there a solution to this that's not an ugly hack? I'm using XCode 9.0.1. I wish Xcode / iOS had a normal build system... coming from Linux/Android, I like many things about the iOS ecosystem but the build system is just ridiculous.
I've seen this problem in a mixed Objective-C/Swift framework and my solution was to include the module name as the directory part of the include. In your case it would be
#import "Example/Example-Swift.h"
instead of
#import "Example-Swift.h"
This is actually documented in the Importing Swift into Objective-C subsection of Importing Code from Within the Same Framework Target at https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html

Modules are disabled - but why?

I'm struggeling with Modules in a project. Where I use #import I get "Use of '#import' when modules are disabled". But why are they disabled?
In my build settings I have "Enable modules (C and Objective-C)" set to Yes for all targets.
Setting "Link Frameworks Automatically" to Yes or No does not impact this (compile-time) error
Although the project used to have Objective-C++ and some C++ code, it doesn't anymore. Are there any project-settings I can have missed that were set because of this?
I have no more .pch files in the project, and the build settings have no mention of them
I use CocoaPods (0.39.0) with "use_frameworks!" and the modules I wish #import are from there. But the same error happens if I replace the '#import ' or '#import ' with '#import Foundation;' and '#import UIKit', so I expect this is not related
The project is from pre-iOS7 so I might have missed a setting that used to be on by default
The project requires iOS 8 and builds against iOS 9.2.
I realize that loading third-party modules will probably slow down the apps loading time. I'm converting to CocoaPods with use_frameworks! so that I can measure by how much. If it's not too bad, I'd like to use as I'm planning to move multiple swift-only parts of the codebase into their own frameworks (as open source coocapods)
I believe that this is not be a duplicate of other questions on SO since I've gone through the ones I found (big thank-you to this one), followed the links, re-watched WWDC'13 session 404, and read the related posts on Apples forums, so I believe I've done my homework. :-)
In my project I have a bridging header to bridge from ObjC to Swift, and there is a generated header file to bridge from Swift to ObjC. It turns out that if the bridging header referenced headers where the implementation file referenced the bridge file from Swift to ObjC, module support is disabled. So be careful about what you put in your bridging file, and be careful about when you import the generated -Swift.h file.
Firstly go to the terminal and type xcode-select -p. It should say, /Applications/Xcode.app/Contents/Developer. If it doesn't, then type, sudo xcode-select -s /Applications/Xcode.app and hit enter and type in your password.
If that doesn't fix it, try deleting your project's derived data directory. Go to the Projects view and delete the derived data for your project. Then clean your build folder (command-shift-K). Run Analyze (command-shift-B) and resolve any issues in blue and yellow.
Now if #import is still not working, create a brand new XCode project. Verify that #import works in it. If it doesn't, then your XCode installation got screwed up probably, or your HDD is dying. Delete XCode and re-download it, see if that works. Restart into the recovery partition and see if you have some disk issues (unlikely, but hey).
If #import works in the new project, try taking all your from your current project and copying them into the new project. Make sure you have the latest version of cocoapods and then freshly install your pods into the new project.
If all of that doesn't fix it, you probably left an #end statement out somewhere or have a missing } ...

Trouble with an .h import

As a beginner in ObjectiveC I need some help.
I'm working on a phonegap plugin for IOS (so, written with objective C). I use some open source code but I got an error with an .h import.
My architecture look like:
myFmk.framework/
myFmk.framework/ABCDE/myFmk.h <== in a sub folder
myFmk.framework/myFmk <=== this is a file
myPlugin.h
myPlugin.m
In myPlugin.h I have #import and in "myFmk.framework/myFmk" file I have only one line "ABCDE/".
I thought that this file do a redirection of the absolute import (with brackets) but my complier told me that "myFmk/myFmk.h" is not found.
I tried to find some documentation about this feature but I wasn't able to find its name... do you have this documentation or the feature name?
Thks.
Is the framework added using a cocoapod? If not, did you follow the instructions properly for adding it to your project? It would probably help if you posted the framework you are experiencing problems with.
If this is a framework that is added to your project properly and you are unable to import there are a few things you should check. First, go to your project settings (click on the project at the very top of your file tree in the left column) and then look for "linked libraries". See if the library is listed there. If not click the + and try to add it.
If this framework was added via cocoapods another thing to check is search your file structure for libPods.a. If it is red, I find sometimes it is helpful to delete it, close the project and run pod install again.
Also if you installed the project via cocoapods remember to open the workspace and not the old xcode project file.
I have also experienced this problem when my header search paths and other linker flag paths were wrong. Linker Flags should be $inherited if this is a cocoapod. In my projects most Header search paths are $inherited too.
If none of this is helpful please provide more information such as how this framework was added to your project and what the framework is. Also let us know if you get any error messages.

Xcode 7 doesn't autocomplete if using bridging header

So, the problem is that when I import anything in the Xcode 7 using Bridging Header Xcode doesn't autocomplete my code, no matter if I import given framework, header file in my current .swift, if it's just in bridging header Xcode doesn't autocomplete.
Though things are different dependently on framework, if I import Parse framework Xcode doesn't autocomplete at all, like no NSString, no other basic stuff.
When I tried to import FacebookSDK, Xcode autocompletes basic stuff like NSString, but it doesn't autocomplete FacebookSDK related stuff.
Also I tried running same project in Xcode 6 and there autocomplete works properly. Is it something wrong with my Xcode 7 or the frameworks?
I already tried deleting cache, derived data, reinstalling Xcode 7 but none helped.
Any tip?
The solution that worked for me is to make sure you put an individual path for each framework you include in your project as in the screenshot below.
Obj c.
Importing .h files into other .m files in the same project.
For time being i am type casting as work around.
The Facebook SDK frameworks weren't showing up in code completion for me. What finally worked was copying the framework files into the Project directory, though the Facebook official instructions recommend using references to the 'Documents' folder.
I tried the solutions from Morgan and Van Du in adding specific directories to the framework search paths, and doing recursion, but no dice for me. Had to fully copy into project directory (running Xcode 7).
after I have tried every solution at stackoverflow I remove all custom plugins – and this was it.
Xcode -> Windows -> Package Manager (in my case it was something about hightailing strings)

external framework File/File.h (Parse/Parse.h) file not found

So every time I update my app, Xcode claims not to be able to find a particular external framework even though it's there. It's happened again with Xcode 6 and my usual methods (I'm fairly inexperienced, so these basically involve clicking and typing things until something happens (I exaggerate but not by much)) aren't working.
I'm getting a Lexical or Preprocessor Issue error that says 'Parse/Parse.h' file not found.' But here are screenshots of it in the project and added to the library:
I also followed the steps in the most upvoted answer at ‘ld: warning: directory not found for option’ but still nothing.
Any idea what to do? Any idea at all? I'm tearing my hair out here.
Actually I was facing the same problem but after doing lots of (removing/adding parse framework) efforts I come to know that parse.framework is already added and error was still there.
Real Problem was not in link Binary for main project but it was with Tests link Binary.
Lets say your project name is "project1" and Xcode create one more folder with it called "project1Tests". So select "project1Tests" and add parse.framework in link Binary.
Check out the hierarchy:
PROJECT
project1
TARGETS
project1
project1Tests (you need to select this to add parse framework).
Hope this would help you resolve this issue.
I had this error also. I'm developing in Swift, so I added a "bridge header" as described in this Parse blog post.
The reason I got the "Parse.h not found" was that my project name contained spaces. (For project name I mean the Product Name you enter when creating a new project, which determines your folder's name.) The first day all went well, but after closing and opening Xcode, it turns out that Xcode interprets the words separated by spaces as different paths.
To fix this, you can go to Build Settings -> Search Paths -> Framework Search Paths and add an "\" before each space. (If you double click the path you'll see that Xcode shows each word separated by space as a different entry.)
Also note that the bridge header with #import <Parse/Parse.h> it's not compulsory: you can simply do import Parse.
All I had to do was remove Parse.framework from this list by highlighting and pressing delete.
Then I went down to the plus sign at the bottom of that list and had to select Add Other and manually locate the downloaded .framework file.
In my case, the error went away after I added the path to the directory where Parse.framework was to the Frameworks Search Paths Build Setting:
My project didn't even have an entry for that setting, so you may need to create it as well.
I had the same issue when upgrading parse to 1.4v. You have to delete Parse.framework from Framework List and from the project directory, when removed from both places copy again and check "Copy items to destination's group folder". It worked for me.
Its work for me.
Just go to Build Active Architecture Only and Debug should be yes and Release should be No
In my case I had to do one more thing additional to Sukhchais' answer.
It seems that though the parse.framework appears in the 'link Binary with Libraries' list for the targets, they might not have linked properly for some reason. Just remove parse.framework from the list and add it again as mentioned. By that way I was able to resolve my issue.
Just to Share my findings in case if somebody might have the same issue:
Accidentally we had two references of Parse.framework inside our source code base at two different places. And a reference of Parse.framework was linked in Build Phases of the target, from the first place. But when the app is compiled, Xcode was not smart enough to get a reference and trowed an error: "Lexical or Preprocessor Issue" error when "Parse/Parse.h" is imported in .pch file.
After spending couple of hours by trying various options, removed a reference of Parse.framework from the source base and kept only a single reference. This solved the issue.
And the app compiled successfully :)
For people coming from Ionic + Cordova if you are getting this error I solved it by removing my current parsePlugin and replacing it with this fork.
For simplicity, I used these console commands (Replace PARSE_APP_ID and PARSE_CLIENT_KEY with your keys in the Parse Console):
cordova plugin rm com.parse.cordova.core.pushPlugin
cordova plugin add https://github.com/grrrian/phonegap-parse-plugin --variable APP_ID=PARSE_APP_ID --variable CLIENT_KEY=PARSE_CLIENT_KEY
Ok, so I was having this problem as well. I uninstalled all my pods, reinstalled them again, and had no luck.
So the good news (and bad news considering the time I spent trying to find the problem) is that I eventually managed to solve it. Apparently, you have to import Foundation/Foundation.h before parse. I don't know whether this will work for you or not, but I tried everything on the net, and only this seemed to work. If you have any instances of this:
#import <Parse/Parse.h>
#import <Foundation/Foundation.h>
flip it around so that Foundation is declared first:
#import <Foundation/Foundation.h>
#import <Parse/Parse.h>
I also read somewhere that some people had issues with Facebook SDK and Parse SDK import. Apparently, the two have Bolt.Framework in common or something, which causes error. I removed Facebook SDK as well, which at first didn't make any difference. I hope I could help.

Resources