我想学习 cocoa touch 框架,我的代码和很多 google 搜索结果一样,但都不行。
我想创建一个可以写入和读取 json 文件的重用代码,并且可以被主项目应用程序调用,所以我创建了一个简单的 cocoa touch 框架只是为了测试,我已经将框架拖到主项目中,添加了它在嵌入式二进制文件中,但是当我构建应用程序时,它总是在 [let a = testClass]
主项目中的这一行出现错误消息,下面是错误消息:
'testClass' is unavailable: cannot find Swift declaration for this class
我有什么地方做错了吗?
cocoa touch框架代码:
import Foundation
public class testClass : NSObject {
public static func tData() -> String {
return "path"
}
}
应用代码:
import UIKit
import test
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let a = testClass
}
最佳答案
我认为您应该尝试将 init()
方法添加到您的 testClass
public override init() {
super.init()
}
关于ios - 创建一个 cocoa touch 框架不能在主项目中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53279043/