本文介绍了创建和导入 swift 框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Swift 编程的新手.我需要创建纯 swift 框架并将其导入到我现有的纯 swift 项目中.当我尝试导入 swift 框架时,出现此错误留言:

I'm 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 errormessage:

"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 评论答案 -我尝试将所有框架文件添加到我的项目根文件夹和项目文件夹内,但再次出现相同的错误

@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.

  1. 创建一个框架项目,例如名为FooKit".(Cocoa Touch Framework 待选)
  2. 创建一个.swift"文件并向其添加一个公共符号,例如public func foo().
  3. 创建一个使用端(应用)项目.(我选择了Single View Application)
  4. 用Finder打开FooKit"的根目录,将FooKit.xcodeproj"拖到那里,通过Project Navigator拖放到app项目中.
  5. 在应用的Build Phases 设置中将FooKit"添加到Target Dependencies.
  6. 将FooKit.framework"添加到应用程序的General 设置中的Embedded Binaries.
  1. Create a framework project, for example named "FooKit". (Cocoa Touch Framework to be selected)
  2. Create a ".swift" file and add a public symbol, for example public func foo(), to it.
  3. Create an use-side (app) project. (I've chosen Single View Application)
  4. Open the root directory of "FooKit" by Finder, drag "FooKit.xcodeproj" there and drop it into the app project via Project Navigator.
  5. Add "FooKit" to Target Dependencies in the app's Build Phases setting.
  6. 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 框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 14:28