What Is an Umbrella Header

What is an umbrella header?

The umbrella header is the 'master' header file for a framework. Its use is that you can write

#import 

instead of

#import 
#import
#import
#import

and so on.

For me, is included in . Maybe it is not for you? In that case, add the

#import 

manually.

Umbrella Header Not Found When Changing Target Name or Product Name of Framework

It turns out the "umbrella header" is no other than the 'main' header for the framework that is created automatically by Xcode when you first create the project or framework target, and it must have the same name as the target (as explained, for example, here).

As to why both target and product must me named the same, I can only guess it has to do with keeping linking not too complicated (Apps are not 'linked against', so I guess there is no damage in the product name being anything you want).

I was trying to get away with a Single Header to Rule Them All (platforms), using TargetConditionals.h etc. to import either Cocoa.h or UIKit.h, which is impossible, because Xcode won't let you use the same name for both targets, and those have to match the name of their headers!

So, I settled for:

  • : Classic. Accept No Substitutes. Exclusive for iOS, and

  • : Now Available on the Mac too! - From the People Who Brought You MyFramework

Swift Framework: Umbrella header '[...].h' not found

This will happen, when the Always Search User Paths setting is enabled for the Framework target.

Setting it to No will resolve that error.

IMHO this is a bug in the Swift Compiler and I have filed a radar with Apple.

See rdar://21038443

Add import to module_map or umbrella header

By the way, I found the solution! /p>

I created the custom umbrella headerMyPod/Sources/MyPod-umbrella.h.

And added imports of pods which I want to be available with import MyPod:

@import MyAnotherPod;

Then I created the custom modulemapMyPod/MyPod.modulemap:

framework module MyPod {
umbrella header "MyPod-umbrella.h"
export *
}

And finally in ./MyPod.podspec:

# Add MyPod-umbrella.h to sources
s.source_files = "#{s.name}/Sources/**/*.{swift,h}"

# Select custom module map
s.module_map = "#{s.name}/#{s.name}.modulemap"

After these changes I just can write:

import MyPod
// And it also imports MyAnotherPod like
// import MyAnotherPod


Related Topics



Leave a reply



Submit