'Using has_include in multi target is not working as expected

The iOS project has two target with different dependencies, podfile like this

source 'https://github.com/CocoaPods/Specs.git'  # 官方库

target 'MultiTargetDemo' do
  pod 'AFNetworking'
end

target 'MultiTargetDemo_other' do
  pod 'SDWebImage'
end

ViewControll.m

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
#if __has_include(<AFNetworking/AFNetworking.h>)
    NSLog(@"has AFNetworking");
#endif
    
#if __has_include(<SDWebImage/SDWebImage.h>)
    NSLog(@"has SDWebImage");
#endif
}

pod install and run any one target. I thought it printed "has AFNetworking" or "has SDWebImage", but it printed "has AFNetworking" and "has SDWebImage".

What I'm missing? How do I know if a dependency exists? Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source