Reputation: 16256
I have this code base that I decided to turn into a framework to reuse in my future apps.
So I went ahead and created an Xcode Project for Cocoa Touch Framework.
To keep things simple (and workspaces out of the picture, at least until I grasp the basics of frameworks), I created a "test-bed" iOS app that embeds/depends on/links to the framework as an additional target to the same project (not a separate project). The idea, of course, is to use this app to test my frameworks capabilities as I add or modify them.
So my project has two targets:
...And of course, two schemes (one to build each):
I am also modifying the code so that it works both on iOS and macOS. Warning: no umbrella header found for target 'MyFramework (macOS)', module map will not be generated.
Additionally, I am also modifying the code so that it works both on iOS and macOS.
So I added two more targets:
...aslo setup so that the app target-depends, links to, and embeds the framework.
Next, I decided to do some cleanup and file rearranging, to keep things tidy and making sense before the number of files starts to grow further.
After some trial and error, I discovered a few things:
1) If I change the target name for the iOS Framework and try to build the iOS app, I get the following warning:
/Users/Me/Projects/MyFramework/Code/MyFramework/:1:1: Umbrella header for module 'MyFramework' does not include header 'PublicHeaderXX.h'
...for each of the public header that are included in my master header:
// In this header, you should import all the public headers of your framework
// using statements like #import <MyFramework/PublicHeader.h>
#import <MyFramework/PublicHeader01.h>
#import <MyFramework/PublicHeader02.h>
#import <MyFramework/PublicHeader03.h>
...
2) If I change the product name of the iOS framework in Build Settings, I get the error:
Lexical or Preprocessor Issue | 'MyFramework/MyFramework.h' file not found
...pointing at the location where I import it in the app source code:
#import <MyFramework/MyFramework.h>
for the Mac framework target, I can get away with changing the Target Name, but if I change the product name, I get the warning:
Warning: no umbrella header found for target 'MyFrameworkMacRenamed', module map will not be generated
So I ask...
Is there a way to set the target names and product names I want for each framework target?
I'm sure there must be something somewhere that I should "modify to match" and eliminate some discrepancy, but I'm new to frameworks and can't figure it out ... (What is an 'umbrella header' anyway?)
Upvotes: 3
Views: 7152
Reputation: 129
I did a lot of reading and trying. My solution is combined:
Now it works.
Upvotes: 0
Reputation: 16256
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:
<MyFramework/MyFramework.h>
: Classic. Accept No Substitutes. Exclusive for iOS, and
<MyFrameworkMac/MyFrameworkMac.h>
: Now Available on the Mac too! - From the People Who Brought You MyFramework
Upvotes: 6