Importing Objective C library in Swift Error - objective-c

I'm trying to import https://github.com/rFlex/SCRecorder in my swift project. I added SCRecoder.xcodeproj to my project and added
#import <SCRecoder/SCRecoder.h>
in my bridging header but it gives me an error
SCRecoder/SCRecoder.h file not found
then I tried
On the SCRecorder project:
Set Build Settings > Packaging > Public Headers Folder Path to include/$(TARGET_NAME)
Add SCRecordSession to Build Phases > Headers > Public
Move Project headers to Public headers
But still same error, any idea on what I did wrong? or the correct way to do it?

delete SCRecoder.xcodeproj file and simply add all .h,.m files and frameworks in SCRecoder

The correct (in my opinion) and easy way to do it is by using Cocoapods.
When adding the library with drag and drop make sure you are selection "copy if needed".
With Cocoapods installed , just edit the file adding "pod 'SCRecorder', '~> 2.4'" and install.

Related

bridging header problem compiling project on Mac mini despite compiling and running perfectly on macBookPro

I am running this project on my MBP and works fine , upon pulling from the repo or even copying the entire project to my Mac mini the errors in the image happen .
I am sure it works (verified adding the bridging header correctly and setting the appropriate flags in the build settings for the target as it works on the MBP)
my project is in swift , the library to import is written in objective c and I am running Xcode 9.4.1 on both machines
any help is appreciated
edit :
- I tried uninstalling and reinstalling macOS and Xcode and the error still persisted
- error msgs : "/Users/******/Desktop/folderName/folderName/Bridging-Header.h:9:9: error: 'PayFortSDK/PayFortSDK.h' file not found
import
^
1 error generated.
:0: error: failed to emit precompiled header '/Users/******/Library/Developer/Xcode/DerivedData/projectName-hjvpkqxmenpclmebdbrkxcarqoap/Build/Intermediates.noindex/PrecompiledHeaders/Bridging-Header-swift_27LSG8YDJOKNN-clang_13WCR1S0OL464.pch' for bridging header '/Users/******/Desktop/folderName/folderName/Bridging-Header.h'"
EDIT : found solution :
1- deleted framework files and old bridging header
2- added new bridging header with a new name and modified the name in buildSettings
3- added framework files again under Frameworks
4- some files had different targets(main target - testing targets) / unified all files targets
5-clean/ index / build Succedded
SecondEDIT : ** another branch / same project **
there was another bridging header is the project folder that was not added to the project after deleting it everything worked as expected
check your build settings, there is your bridging header path is set or not and then also clean your derivedData Folder,then clean and run your project

umbrella header for module 'myFramework' does not include header 'otherFramework.h'

My Swift / iOS9 framework 'viewer_protocol' uses another and external Objective-C framework (CocoaAsyncSocket). I'm using Carthage to build CocoaAsyncSocket. So far everything works fine: In have an example App inside my framework Xcode Project using my framework without any problems.
Now I want to use my Framework in a different Xcode Project - although using Carthage. I include only my Framework as a dependency and Carthage automatically resolves the dependencies to CocoaAsyncSocket. I embedded both frameworks into this new Xcode Project and build my App: Everything works fine here - except one warning I can't rid off:
/Users/John/Repositories/my_project/<module-includes>:1:1:
Umbrella header for module 'my_project' does not include header 'GCDAsyncSocket.h'
This is my framework header:
#import <UIKit/UIKit.h>
//! Project version number for my_project.
FOUNDATION_EXPORT double my_projectVersionNumber;
//! Project version string for my_project.
FOUNDATION_EXPORT const unsigned char my_projectVersionString[];
// In this header, you should import all the public headers of your framework
using statements like #import <my_project/PublicHeader.h>
#import <CocoaAsyncSocket/CocoaAsyncSocket.h>
As you can see CocoaAsyncSocket.h is imported. Furthermore inside my framework the CocoaAsyncSocket.h file is included:
What I am missing here? I'm using several others external frameworks inside my framework, there're no warnings for them - all of these external frameworks are written in Swift - CocoaAsyncSocket is pure Objective-C.
This is my frameworks module.modulemap:
framework module my_project {
umbrella header "my_project.h"
export *
module * { export * }
}
module viewer_protocol.Swift {
header "my_project-Swift.h"
}
Update
I found a solution: Changing the import statement in my framework header from
#import <CocoaAsyncSocket/CocoaAsyncSocket.h>
to
#import "CocoaAsyncSocket/CocoaAsyncSocket.h"
Now Xcode finds the header file and the warning disappears.
I recently ran into same issue. Apparently I had header file set as public in target membership, but it was not exposed in umbrella header. Fixed issue by making header file with project access instead of public.
I had the same issue. Seemed to be related to old build files.
The standard Xcode problem fixer worked for me:
Clean project (Product > Clean Build Folder)
Deleted derived data
Restart Xcode
I had the same issue today
Umbrella header for module 'HockeySDK' does not include header 'BITHockeyBaseViewController.h'
and the solution was
1.build and run project and go-to Report Navigator
2.look at the warning, click to expand details
it will so you the file name where you need to make change
as you can seen in below screen shot
So i just updated my import statement in AppDelegate.m file
New
#import "HockeySDK/HockeySDK.h"
Old
#import <HockeySDK/HockeySDK.h>
and issue gone..
hope this will help someone. who are coming here for solution.
For me the solution was as follows:
1) Each Objective C framework has 1 header file that contains all the:
#import ...
#import ...
#import ...
2) Make sure that this file imports the missing header.
3) Build the project again, it should remove the warning.
Alternatively, you may have exposed files within the Public area of your framework's build phases that should actually be moved back to the Project area.
If you don't want those files to be within your framework's umbrella header so they're publicly accessible, you can revert this.
Goto Framework -> Target -> Build Phases and drag to move the unnecessary header files from Public to Project.
Just for completeness if your header is set to public in :
Build Phases > Headers
You should either
Include the import in your main header as others have mentioned
OR
Move that header to "private" if it doesn't need to be exposed
We got this recently and it was due to corruption in DerivedData. Deleting that folder fixed the problem.
For others :
In my case I already move the headers I want to expose from my framework, from "project" to "public" (Build phases of the framework target)
Then Xcode gave my this warning.
Xcode is telling us that we also need to add #import "name of header in the warning> in the public header file that was created with framework, so the clients (of the framework) will know this header.
So The Fix:
1.go to the framework public header file.(the one what created by xcode when you created the framework) .
2. add #import "the-name-of-the-header-in-the-warning.h"
In my case (Obj-c framework):
Umbrella header for module 'opus' does not include header 'opus_multistream.h'
I needed to change:
#import opus.opus_defines;
into
#import opus;
(I don't have in #import "....h" or #import <....h> for frameworks)
Take a look at this post:
#import vs #import - iOS 7
It goes over the concepts of the new module importing.
I had my own custom framework and after adopting the new method to import objective-c framework
old:
#import <MyFramework/MyFramework.h>
new:
#import MyFramework;
it took care of the warning/
Deleting DerivedData did the trick for me. Try running the below command and see if it works.
rm -rf ~/Library/Developer/Xcode/DerivedData
trying to fix a archive build error led me to this error and post
my solution was real simple but took forever for me to figure out.
when i ran $ pod install it generated a workspace for me in the same dir as my .xcodeproj file.
however i had already created a workspace to use as its parent directory.
so then i simply deleted my old workspace and went with the one that pods created
hope this helps someone!
glhf!
For me the fix was rather simple, commit all your changes and build again. The warning disappeared.

Bridging File Not Found

The bridging file is added, but keeps showing the error.
My Bridging Header File is correctly setup because the other imports are successful.
I would advise you to use CocoaPods to handle external frameworks. Here is SlackTextViewController. If you still want to use copied version, make sure you add the files to your project. Try copying the files to your project folder using Finder and then use Xcode File -> Add files to "YOUR_PROJECT"

How to link third party libraries properly in iOS

I'm new in iOS development, and met this library linking problem in last few days.
I was trying to use GMGridView in a project, but cannot make it working.
This project is shipped as static library, so I just drag the xcodeproj file in my project. Then I added libGMGridView.a in Link Binary With Libraries, GMGridView in Target Dependencies. I also added the path in Header Search Paths.
However, Xcode still report .h file not found error when I tried to import GMGridView.h.
Could anyone give me a hand on this? Thanks in advance!
Had the same issue!!! Made it work!!!!
soooooooo:
copy GMGridView folder from https://github.com/gmoledina/GMGridView to your project dir
in xcode right click on any file group and choose add files
find GMGridView folder in your folder dir and choose GMGridView.xcodeproj - (dont copy, create groups not folders, add targets)
go to your project targets - search - HEADER_SEARCH_PATHS add- GMGridView/**
select Building phases in settings - choose target dependencies and add GMGridView
select Building phases in settings - link binary libraries and add libGMGridView.a
import should be:
#import "GMGridView.h"
#import <QuartzCore/QuartzCore.h>

compilation warning: no rule to process file for architecture i386

How can I resolve this warning?
[WARN]warning: no rule to process file
'$(PROJECT_DIR)/MyApp/MessageCell.h' of type sourcecode.objj.h for
architecture i386
Click on your project, and check that this file is not present in the tab Build Phases. Normally no header files should stay here. Clean and build it again, it should work!
Graphical guide for Xcode 4.x to remove this warning:
http://joytek.blogspot.tw/2011/09/xcode-4-warning-no-rule-to-process-file.html
We can resolve this issue by simply following the steps below:-
Some .md, .mdown .h files are included in the Compile Sources
Step 1) Select Project Navigator
Step 2) Select your project
Step 3) Select your targetStep
Step 4) Select Build PhasesStep
Step 5) Move files which we don't want the compiler to process from Compile Sources to Copy Bundle Resources
Check this
If you are getting this warning from your cocoapod you ned to make sure the s.source_files is set correctly in the .podspec.
For example I originally included all files with this line in my .podspec
s.source_files = "MyUIElements/**/*"
I was getting this compilation warning for some font files I had in the pod. You control which files show up in BuildPhases -> CompileSources on pod consumption like this:
s.source_files = "MyUIElements/**/*.swift", "MyUIElements/**/*.h"
My problem was't header files because under Target > Build Phases > Compile Resources there weren't any .h files to begin with. The system was complaining about some other files. I followed this link which basically said delete the files the system was complaining about but instead I cntrl + dragged them to Copy Bundle Resources.
The easiest way to search for the files is to use the Filter in the upper right hand corner:
Here are the directions from the link: