And then it could be linked and used from Objective-C with the
#import MyStaticLib;
syntax.
If so, how, exactly, do you do this.
You can create a static library with .modulemap file to use #import syntax
[Create Objective-C static library]
If you can edit the library Xcode project you can create a *.modulemap file and set it to the MODULEMAP_FILE Build Setting.
Sample map file from CocoaLumberjack:
framework module CocoaLumberjack {
umbrella header "CocoaLumberjack.h"
export *
module * { export * }
}
module CocoaLumberjack.DDContextFilterLogFormatter {
header "DDContextFilterLogFormatter.h"
export *
}
module CocoaLumberjack.DDDispatchQueueLogFormatter {
header "DDDispatchQueueLogFormatter.h"
export *
}
module CocoaLumberjack.DDMultiFormatter {
header "DDMultiFormatter.h"
export *
}
module CocoaLumberjack.DDASLLogCapture {
header "DDASLLogCapture.h"
export *
}
module CocoaLumberjack.DDAbstractDatabaseLogger {
header "DDAbstractDatabaseLogger.h"
export *
}
You can by creating a framework from this static library, you can follow all the instructions here
Once finished, you can import your static library like that:
#import MyStaticLib;
Related
for example, this .modulemap works:
framework module MySDK {
umbrella header "MySDK-umbrella.h"
header "inc/header1.h"
header "inc/header2.h"
header "inc/header3.h"
...
export *
module * { export * }
}
but this one does not:
framework module MySDK {
umbrella header "MySDK-umbrella.h"
header "inc/*.h"
export *
module * { export * }
}
So how can I add multiple header files recursively in .modulemap?
I recommend investigating using umbrella "Headers" instead of umbrella header "MySDK-umbrella.h" for a case like this.
https://clang.llvm.org/docs/Modules.html#umbrella-directory-declaration
I have created .a static library (tested in Xcode for native ios project and Its working fine)
Now I am following this https://github.com/NativeScript/nativescript-plugin-seed to create nativescript plugin using .a static framework.
Plugin structure
module.modulemap file is created by me and it's look like this
module libstaticlibrary {
umbrella header "staticlibrary.h"
export *
}
staticlibrary.h
#import <Foundation/Foundation.h>
#interface staticlibrary : NSObject
+ (NSString *)sayHello;
#end
libstaticlibrary.d.ts also created by me
declare class staticlibrary extends NSObject {
static sayHello():string;
}
Then in helloplugin.common.ts I am trying to access staticlibrary.sayHello() method.
export class Utils {
public static SUCCESS_MSG(): string {
// let msg = `Your plugin is working on ${app.android ? 'Android' : 'iOS'}.`;
let msg = staticlibrary.sayHello();
setTimeout(() => {
dialogs.alert(`${msg} For real. It's really working :)`).then(() => console.log(`Dialog closed.`));
}, 2000);
return msg;
}
I am getting following error.
node_modules/nativescript-helloplugin/helloplugin.common.ts(21,15): error TS2304: Cannot find name 'staticlibrary'.
What is I am doing wrong here?
It's just the TypeScript compiler error, you have to generate typings for your static library (refer docs to know how) or just add this line at top of your file.
declare var staticlibrary: any
I see that you do have a declaration file in your code snippet, if you want to use it you have to include it to your references.d.ts file.
I imported "if_dl.h" in my Swift framework to use sockaddr_dl like this :
module net [system] [extern_c] {
module if_dl {
umbrella header
"/Applications/Xcode_7.3.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/net/if_dl.h"
module * {export *}
}
}
and now I am getting this error:
Declaration of 'u_char' must be imported from module
'Darwin.POSIX.sys.types' before it is required
I tried to add "import Darwin" in the class code but it's not resolving the problem.
I resolved the problem,
Module "types" have to be inside the module "net" and it have to be added before adding "if_dl"
module net [system] [extern_c] {
module types {
header "/usr/include/sys/types.h"
export *
}
module if_dl {
header
"/usr/include/net/if_dl.h"
export *
}
}
I'm trying to implement a framework using swift but the header file is not been updated with the class or the functions:
Here is my code in my swift file:
public class one{
public func two(name:String) -> String {
print(name)
}
}
#objc public class SwiftInObjc:NSObject {
public func bla(){
}
}
After I build this is what I see in my header file:
#import <UIKit/UIKit.h>
FOUNDATION_EXPORT const unsigned char sampleFramework[];
framework using statements like #import <sampleFramework/PublicHeader.h>
How can generate update to the header file?
framework module Test {
umbrella header "Test.h"
export *
module * { export * }
}
This is what my module file looks like. How can I resolve the following warning.
Umbrella header for module 'Test' does not include header 'NewTest.h'
I am not familiar with module files.
You should have a module map
modify the code to-
framework module Test {
umbrella header "Test.h"
export *
module * { export * }
explicit module BFAppLinkResolving {
header "BFAppLinkResolving.h"
link "BFAppLinkResolving"
export *
}
explicit module BFWebViewAppLinkResolver {
header "BFWebViewAppLinkResolver.h"
link "BFAWebViewAppLinkResolver"
export *
}
}