0

To ensure that any project depending on it can use it, a class in an iOS framework must inherit from a class in its pod dependency. To achieve this, the header of the class needs to be made public. However, after doing so, Xcode generates an error stating that it cannot find the header file for the pod dependency when attempting to import headers.

I worked on an Xcode project called 'HelloTargetWithPod' that included a framework called 'Hello'. In my Podfile, I added the AFNetworking library as a dependency for the "Hello" target, using the following code:

platform :ios, '14.0'

target 'Hello' do
  use_frameworks!
  pod 'AFNetworking', '~> 4.0.1'
end

target 'HelloTargetWithPod' do
  use_frameworks!
end

After running pod install and closing "HelloTargetWithPod.xcodeproj", I opened "HelloTargetWithPod.xcworkspace".

Within the "Hello" framework, I created a public class called "MyImageDownloader" and imported the AFNetworking header file using the following code in "MyImageDownloader.h":

#import "AFNetworking/AFNetworking.h"

@interface MyImageDownloader : NSObject

// ...

@end

However, when I tried to compile the project, Xcode generated the error "'AFNetworking/AFNetworking.h' file not found".

In the meantime, there are two additional issues:

  1. If MyImageDownloader.h is not set as public, the error does not occur.

  2. Importing <AFNetworking/AFNetworking.h> in MyImageDownloader.m does not generate an error. Why does it generate an error in MyImageDownloader.h?

  3. If MyImageDownloader.h is set as public and add the following code:

    @class AFImageDownloader;
    
    NS_ASSUME_NONNULL_BEGIN
    
    @interface MyImageDownloader : AFImageDownloader
    
    @end
    
    NS_ASSUME_NONNULL_END
    

    Xcode displays the error message "Attempting to use the forward class 'AFImageDownloader' as superclass of 'MyImageDownloader'".

I have uploaded the relevant project code to this Git repository.

This issue is similar to the Including a pod inside a framework target: file not found. I have tried the solutions provided, but they did not work.

I'm not sure how to resolve this issue, and I'd appreciate any help or advice.

yancaico
  • 1,145
  • 11
  • 21
  • I struggled with this issue for two days but was able to solve it unexpectedly. I selected the framework target that depends on a Pod, went to "Build Settings" > "Packaging" > "Defines Module" and set it to "No". Then I rebuilt the target and the error disappeared. I'm not sure about the exact reason why this worked, but it did solve the problem for me. I hope this information helps you. If you have a more in-depth understanding of this issue, please feel free to share your insights. – yancaico Apr 18 '23 at 08:42

0 Answers0