如何在NativeScript中使用swift库? [英] How to use swift library in NativeScript?
问题描述
我正在尝试在NativeScript中使用此ios-charts库。这个库是用Swift编写的,而不是用Objective-C编写的。我可以用吗?我试图使用它,但它给了我一个错误。我已在以下步骤中使用它:
我已使用
<$ p $在我的nativescript项目中添加了库p>
tns library add ios'library_path'
添加库。然后我使用
为ios平台准备项目.tns准备ios
为了测试是否成功添加库,我在 Xcode
中构建项目,它构建成功,但后来我得到了运行期间出现以下错误。
dyld:未加载库:@ rpath / libswiftCore.dylib
引用自:/ Users / UserNameHere / Library / Developer / Xcode / DerivedData / Build / Products / Debug-iphonesimulator / Charts.framework / Charts
原因:图片未找到
当我设置嵌入内容包含swift代码
到 YES时,我摆脱了这个错误/ code>。但现在当我尝试访问库时
var charts = new Charts();
给出参考错误如下:
ReferenceError:找不到变量:图表
我已经尝试过:
我尝试使用以下方法访问图表:
1。 var charts = new Charts.Swift();
2. var charts = new Charts.Charts();
3. var charts = new Charts-Swift();
4. var charts = new Charts.LineChartView();
5. var charts = require(图表);
6. var charts = require(../../ lib / Charts.framwork);
7. var charts = require(Charts.framework);
所有这些方法都会产生同样的错误。
参考文献
我按照这些链接开发我的项目
Using-native-libraries-in-your-nativescript-apps
使用带有可可豆荚的native-libs:docs.nativescript.org/runtimes/ios/native-libs/CocoaPods
即使我尝试使用Cocoa Pods,它仍然会出现同样的错误。
如果有人试过这个,请告诉我。
您可以查看我的对话框插件:
https://github.com/enchev/nativescript-dialog
我正在使用Swift库SDCAlertView,你可以找到更多信息关于如何在pod和xconfig文件中设置它:
https://github.com/enchev/nativescript-dialog/tree/master/platforms/ios
所有类别在全球范围内最有可能是可用的。例如:
var chart = new BarChartView();
I am trying to use this ios-charts library in NativeScript. This library is written in Swift and not in Objective-C. Can I use it? I have tried to use it but it is giving me an error. I have used it in following steps:
For which I have added library in my nativescript project using
tns library add ios 'library_path'
The library gets added. Then I prepared project for ios platform using
tns prepare ios
To test if library is added successfully, I build the project in Xcode
, it builds successfully, but then I get the following error during runtime.
dyld: Library not loaded: @rpath/libswiftCore.dylib
Referenced from: /Users/UserNameHere/Library/Developer/Xcode/DerivedData/Build/Products/Debug-iphonesimulator/Charts.framework/Charts
Reason: image not found
I got rid of the this error when I set Embedded content contains swift code
to YES
. But now when I am trying to access the library as
var charts = new Charts();
It is giving a Reference error as below:
ReferenceError: Can't find variable: Charts
What I have already tried:
I tried to access Charts using following methods:
1. var charts = new Charts.Swift();
2. var charts = new Charts.Charts();
3. var charts = new Charts-Swift();
4. var charts = new Charts.LineChartView();
5. var charts = require("Charts");
6. var charts = require("../../lib/Charts.framwork");
7. var charts = require("Charts.framework");
All these methods give the same exact error.
References
I followed these links to develop my project
Using-native-libraries-in-your-nativescript-apps
Using native-libs with cocoa pods: docs.nativescript.org/runtimes/ios/native-libs/CocoaPods
Even if I try this with Cocoa Pods, it still gives the same error.
If anyone has tried this, please let me know.
You can check for example my dialog plug-in: https://github.com/enchev/nativescript-dialog
I'm consuming Swift library SDCAlertView and you can find more info about how to setup this in the pod and xconfig files: https://github.com/enchev/nativescript-dialog/tree/master/platforms/ios
All classes most probably are avaialble in the global context. For example:
var chart = new BarChartView();
这篇关于如何在NativeScript中使用swift库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!