How to import private framework headers in a Swift framework?
You need to modify framework A
, So that it export a private module.
Create a private module map file in
A
project. This would be something like this:A/private.modulemap:
explicit module A.Private {
// Here is the list of your private headers.
header "Private1.h"
header "Private2.h"
export *
}In the "Build Settings" of framework
A
target, search "Private Module Map File" line, and make that:$(SRCROOT)/A/private.modulemap
Do not include
private.modulemap
file in "Compile Sources". That causes unnecessary warnings.Clean and Build framework
A
target.In framework B Swift files. you can import the private module like this:
import A
import A.Private
How can I create private module without including private headers into the framework?
Apple doesn't include private modules with their frameworks. Most likely, we shouldn't do that as well.
Import headers from c++ library in swift
You don't import anything in your Swift code when Objective-C headers are imported in the bridging header.
All public interfaces available from the imported files get available in the entire Swift module by default after that.
Sample listing
TDWObject.h
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface TDWObject : NSObject
- (void)someCPPCode;
@end
NS_ASSUME_NONNULL_END
TDWObject.mm
#include <iostream>
#import "TDWObject.h"
@implementation TDWObject
- (void)someCPPCode {
std::cout << "Hello from CPP cout" << std::endl;
}
@end
Some-Bridging-Header.h
#import "TDWObject.h"
main.swift
TDWObject().someCPPCode()
Provided the main.swift file is the entry point of the program, it will print Hello from CPP cout
.
iOS Swift framework: How to import Objective C code into swift framework properly?
The thing is, brigding header doesn't work for Framework targets. Solution is to create module map target to build module map for needed ObjC framework.
Here is example for CommonCrypto: https://stackoverflow.com/a/42852743/1840136; in your case difference should be that script line
header "${SDKROOT}/usr/include/CommonCrypto/CommonCrypto.h"
will be replaced with path to AFNetworking
headers (I'm not sure if you're placing 3rd party libraries just within project or getting from pods, so check by yourself).
Related Topics
Find Where Object Is Retained with Arc
How to Change Label Constraints During Runtime
How to Remove All Navigationbar Back Button Title
Notify Watchkit App of an Update Without the Watch App Requesting It
How to Scroll to the Exact End of the Uitableview
Icon Already Includes Gloss Effects
To Convert Image to Cartoon in iOS
iOS 8.1 Simulator Localization Broken (Nslocalizedstring)
Xcode - Error Itms-90635 - Invalid MACh-O in Bundle - Submitting to App Store
Uitableviewcell with Uiwebview Dynamic Height
How to Find a Specification in Cocoapods
How to Write Init Methods of a Uiviewcontroller in Swift
Auto Layout to Dynamically Size Uilabel Width
Adding Background Image to Uilabel