创建和导入swift框架

编程入门 行业动态 更新时间:2024-10-19 14:31:22
本文介绍了创建和导入swift框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是一个新的swift编程。 我需要创建纯swift框架并将其导入我现有的纯swift项目。 当我尝试导入swift框架,我得到这个错误消息:

不构建Objective-C模块'< myModule>'

Test.h

import Foundation public class Test { class func printTest(){ println 111); } }

Asdf.h / p>

import UIKit public class Asdf:Test { class func echo(){ println (888); } }

myModule-Swift.h

#ifndef< myModule> _< myModule> _Swift_h #define< myModule> _< myModule& _Swift_h #endif

框架构建之后,现有项目并获得此

我做错了什么?感谢您的帮助!

@findall comment answer - 我试图将所有框架文件添加到我的项目根文件夹和项目文件夹,错误

  • 创建一个框架项目,例如命名为FooKit 。 ( Cocoa Touch Framework 待选择)
  • 创建.swift文件并添加公共符号,例如 public func foo()。
  • 创建一个使用方(我选择了 Single View Application )
  • 通过Finder打开FooKit的根目录,拖动FooKit.xcodeproj c。
  • 将添加到目标依赖项设置
  • 将添加到嵌入式二进制文件 c> c> $
  • $ b >现在你可以在使用端应用程序中构建像这样的代码。

    import FooKit func bar(){ foo()}

    I'm a new in swift programming. I need to create pure swift framework and import it in my existing pure swift project. When I try to import swift framework, I'm getting this error message:

    "Could not build Objective-C module '<myModule>'"

    Test.h

    import Foundation public class Test { class func printTest() { println("111"); } }

    Asdf.h

    import UIKit public class Asdf: Test { class func echo() { println(888); } }

    myModule-Swift.h

    #ifndef <myModule>_<myModule>_Swift_h #define <myModule>_<myModule>_Swift_h #endif

    After framework build, i have added framework in my existing project and get this

    What am I doing wrong? Thanks For Help!

    @findall comment answer - I tried to add all framework files to my project root folder and inside project folder, but again got the same error

    解决方案

    I've done with the following steps.

  • Create a framework project, for example named "FooKit". (Cocoa Touch Framework to be selected)
  • Create a ".swift" file and add a public symbol, for example public func foo(), to it.
  • Create an use-side (app) project. (I've chosen Single View Application)
  • Open the root directory of "FooKit" by Finder, drag "FooKit.xcodeproj" there and drop it into the app project via Project Navigator.
  • Add "FooKit" to Target Dependencies in the app's Build Phases setting.
  • Add "FooKit.framework" to Embedded Binaries in the app's General setting.
  • Now you can build like this code in the use-side app.

    import FooKit func bar() { foo() }

    更多推荐

    创建和导入swift框架

    本文发布于:2023-11-17 08:35:54,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1609479.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:框架   swift

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!