我一直在尝试解决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/