ios - 无法使用 swift 4.1 创建自定义框架

标签 ios swift xcode9.3 swift-framework

我一直在尝试解决this问题。所以我想到在 swift 4.1 上创建一个新的简单的新框架。

我的代码是这样的:

public class TestStupidity: NSObject {
    public static var shared = TestStupidity()
    public func hello() {
        print("hello")
    }
}

然而,即使是这一小段代码也不适合我。公共(public)类及其变量不会出现在头文件中。

我已将此项目上传到 GitHub link .

任何人都可以帮我弄清楚我在这里做错了什么吗?

最佳答案

按照以下步骤操作,看看它是否正常工作:

创建 Cocoa Touch Framework 类型的新项目,并将其命名为 Tester

添加名为 TestStupidity.swift 的新 Swift 文件

将问题中的代码添加到文件中:

public class TestStupidity: NSObject {
    public static var shared = TestStupidity()
    public func hello() {
        print("hello")
    }
}

向 Single View App 类型的项目添加新目标并将其命名为 TesterApp

选择 TestApp 目标,然后在“常规”选项卡中单击“嵌入式二进制文件”的 + 号。选择测试器框架

在 ViewController.swift 文件中,将代码设置为:

import UIKit
import Tester

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let testClass = TestStupidity()
        testClass.hello()
    }
}

运行 TestApp 并在输出中看到“hello”。

关于ios - 无法使用 swift 4.1 创建自定义框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49921008/

相关文章:

ios - 显示来自网络的图像时 TableView 滞后

swift - 快速创建 Realm 对象时出错

swift - mapView 中的 MapKit 运行时错误(_ :didAdd:) with clustering

ios - 如何告诉用户你的 iOS 应用程序需要多少内存

ios - 偷看时不调用prepareForSegue

iphone - 实现 UIStepper 时对 "value"的使用不明确

objective-c - 无法在 Swift 中调用采用 int 的 ObjC 方法,因为 Int32 无法转换为 Int

swift - 如何迭代 macOS 应用程序的窗口直到满足条件?

swift - 在 swift 4.1 中使用 nil 合并进行隐式解包时出现意外的 "some()"

ios - 如何根据项目内容从 NSArray 中删除项目