developer tip

Objective-C 프레임 워크를 Swift 프로젝트로 가져올 때 Bridging Header에서 "파일을 찾을 수 없음"발생

optionbox 2020. 9. 7. 08:03
반응형

Objective-C 프레임 워크를 Swift 프로젝트로 가져올 때 Bridging Header에서 "파일을 찾을 수 없음"발생


ObjC 기반 프레임 워크를 가져 오려고하는 Swift 프로젝트가 있습니다. 프레임 워크는 프로젝트 경로 아래의 디렉토리에 있으며 Xcode의 프로젝트에서 참조됩니다. 프로젝트의 'Build Phases'페이지에있는 "Link Binary with Libraries"에도 추가됩니다.

그러나 어떤 이유로 Bridging-Header 파일에 프레임 워크를 포함 할 수없는 것 같습니다. 다음과 같은 오류가 발생합니다.

BridgingHeader.h:5:9: error: 'Parse/Parse.h' file not found
#import <Parse/Parse.h>
        ^
<unknown>:0: error: failed to import bridging header 'BridgingHeader.h'

내가 확인한 사항 :

  1. "Objective-C 호환성 헤더 설치"가 "예"로 설정됩니다.
  2. 헤더 검색 경로에는 프레임 워크에 대한 경로가 포함됩니다.

나는 내가 뭔가를 놓치고 있다고 확신하므로 누군가 단서가 있다면 좋을 것입니다.


해결책을 찾았습니다.

  • "Objective-C 브리징 헤더"설정 (일명 SWIFT_OBJC_BRIDGING_HEADER)은 프로젝트 수준이 아닌 대상 수준에서 설정해야합니다. 프로젝트 수준에서 설정 값을 삭제해야합니다.

(저에게 Xcode 버그처럼 보입니다. 왜 수정했는지 모르겠습니다.)


나는 같은 문제가 있습니다. 예를 들어 모든 가져 오기를에서 #import "HMSegmentedControl.h"변경했습니다 #import <HMSegmentedControl/HMSegmentedControl.h>.


lib사용자 헤더 검색 경로에 디렉토리 를 추가해야했습니다 .

테스트 대상 설정-사용자 헤더 검색 경로

제 경우에는 lib디렉토리에 .a-library 파일과 일부 헤더 파일이 포함되어 있습니다. 이들은 브리징 헤더 파일에 포함되어 있습니다. 그러나 신속한 컴파일러는이를 찾지 못했습니다. ${PROJECT_DIR}/lib사용자 헤더 검색 경로에 추가했을 때만 테스트 대상을 구축했습니다.

(Mavericks 10.9.5에서 Xcode 6.2를 사용하고 있습니다)


완전히 다른 원인으로 동일한 오류 메시지가 발생했습니다.

설정:

  • 앱 타겟, 모든 Obj-C 코드
  • 단일 신속한 테스트 케이스 및 앱 코드를 참조하는 브리징 헤더가있는 단위 테스트 대상

두 번째 빠른 테스트 케이스를 추가했을 때, 청소 후 (또는 팀 동료의 컴퓨터에서) 단위 테스트 대상을 빌드 할 때이 오류가 발생했습니다.

단위 테스트 대상에 더미 Obj-C 클래스를 추가하여 수정되었습니다.


이것은 어떻게 든 나를 위해 트릭을했습니다.

  • 깨끗한 프로젝트
  • 빌드 폴더 정리
  • Xcode 다시 시작

This error appeared when installing with Cocoapods the library CocoaImageHashing. The problem was that the search paths were wrong. So at the Target level, in Build Settings -> Search Paths -> Header Search Paths, the paths were corresponding to non existing folders, for example "${PODS_ROOT}/Headers/Public/CocoaImageHashing", when the folder structure Headers/Public/ did not exist. I added the path ${PODS_ROOT}/CocoaImageHashing and the error disappeared.


Well its little strange but I guess you have to add a resource to your "Copy Bundle Resources" phase of your test target to make it load all headers from your main app target. In my case, I added main.storyboard and it took care of the error.

여기에 이미지 설명 입력


If using cocoapods, try reinstalling the pods by running the following command.

pod install

If helps anyone.

In my case my obj-c files were added has a reference folder (the blue folders in xcode) and the header couldn't find them. Just added the files, not the folder, from the finder to xcode and solved.


I had the same problem. For me the reason was that I was using the same bridging-header for both my App and my Today Extension. My Today Extension does not include Parse, but because it was defined in the bridging-header it was trying to look for it. I created a new bridging-header for my Today Extension and the error dissapeared.


I had an issue and fixed it after spending 2 hours to find. My environment as below:

cocoapod 0.39.0

swift 2.x

XCode 7.3.1

Steps:

  1. project path: project_name/project_name/your_bridging_header.h
  2. In Swift section at Build Setting, Objective-C Bridging Header should be: project_name/your_bridging_header.h
  3. In your_bridging_header.h, change all declarations from .h to #import
  4. In class which is being used your_3rd_party. Declare import your_3rd_party

This happened to me after adding/renaming current configurations and it makes sense.

Every configuration makes use of Configurations Set generated by cocoapods so these things needs to match.

So if you add/rename configurations, these will need to use the right configuration sets, and for that running pod install will do it.


My framework was working before and suddenly stopped working, and none of these answers were working for me. I removed the framework in Build Phases > Link Binary With Libraries, and re-added it. Started working again.


I had just duplicated an existing scheme and added another configuration to the project. I had to add a configuration with the same name to the framework's project in order for it to also build in the same DerivedData/($AppName)/Build/Products/($CONFIGURATION_NAME) folder. Otherwise the .framework file doesn't get created and therefore can't be imported.


I ran into the same issue today when trying to use a pod written in Objective-C in my Swift project, none of the above solutions seemed to work.

In the podfile I had use_frameworks! written. Commenting this line and then running pod installagain solved this issue for me and the error went away.


(Updated as of May 27, 2017)

Xcode 8. Swift Project - importing Objective C.

Things to know:

  1. Bridging header file MUST be saved within the project's folder. (i.e. not saved at the same level that .xcodeproj is saved, but instead one level further down into the folders where all your swift and objective c files are saved). It can still find the file at the top level, but it will not correctly link and be able to import Objective C files into the bridging header file
  2. Bridging header file can be named anything, as long as it's a .h header file
  3. Be sure the path in Build Settings > Swift Compiler - General > Objective C Bridging Header is correctly pointing to you bridging header file that you made
  4. IMPORTANT: if you're still getting "not found", try to first empty your bridging header file and erase any imports you currently have written there. Be sure that the bridging header file can be found first, then start to add objective c imports to that file. For some reason, it will kick back the same "not found" error even if it is found but it doesn't like the import your trying for some reason
  5. You should not #import "MyBridgingHeaderFile.h" in any of your objective C files. This will also cause a "file not found" error

I had similar problem and only one solution worked out for me. I tried everything suggested, and I knew that I set my bridging header fine, because I had some other lib working.

When I copied library (drag and drop) into the project, without Cocoapods, only after that I could import headers without errors.

I used facebook/Shimmer library.


I had a similar issue with pods. Basically trying to run my UI tests, Xcode complained about missing pods. Solution to this was much simpler than any described above:

  1. go to project file (main not a target)
  2. click on the "Info" tab (most left)
  3. set proper pod configuration for UI tests target ("Configurations" section right under "Deployment Target")

Working!

I found it in a thread: https://github.com/CocoaPods/CocoaPods/issues/2695

Sounds a bit like a bug for cocoa pods but I can see reasons why it might be tricky case.


In my case I just had to quit the simulator...


Clean project,Clean build folder,Restart Xcode. i just remove path at project goto > Build Settings > Search the keyword. Swift Compiler - General -> Objective-C Bridging header worked for me.


August 2019

In my case I wanted to use a Swift protocol in an Objective-C header file that comes from the same target and for this I needed to use a forward declaration of the Swift protocol to reference it in the Objective-C interface. The same should be valid for using a Swift class in an Objective-C header file. To use forward declaration see the following example from the docs at Include Swift Classes in Objective-C Headers Using Forward Declarations:

// MyObjcClass.h
@class MySwiftClass; // class forward declaration
@protocol MySwiftProtocol; // protocol forward declaration

@interface MyObjcClass : NSObject
- (MySwiftClass *)returnSwiftClassInstance;
- (id <MySwiftProtocol>)returnInstanceAdoptingSwiftProtocol;
// ...
@end

참고 URL : https://stackoverflow.com/questions/27496055/getting-file-not-found-in-bridging-header-when-importing-objective-c-framework

반응형