[英]Can you share a .swift file between an app and its extension if it relies on app-only code
I have the following set of files in my project: 我的项目中有以下文件集:
The IAPHelper class uses the objective-c through a bridging header. IAPHelper类通过桥接标头使用Objective-C。 I was wondering if I could use the IAPHelper class in both my app and its app extension like this: 我想知道是否可以在我的应用及其应用扩展中使用IAPHelper类,如下所示:
(Setting IAPHelper's target membership) (设置IAPHelper的目标成员)
Without making KeychainWrapper being a member of both classes. 无需让KeychainWrapper成为这两个类的成员。
No it does not seem to work. 不,它似乎不起作用。
I made TestClassOne
我做了TestClassOne
import Foundation
class TestClassOne {
static internal func addOneOne() -> Int {
return 2;
}
}
TestClassOne
is only part of one target. TestClassOne
只是一个目标的一部分。
I made TestClassTwo
我做了TestClassTwo
import Foundation
class TestClassTwo {
internal static func callTestClassOne() -> Int {
let i = TestClassOne.addOneOne()
return i
}
}
TestClassTwo
belonged too both targets. TestClassTwo
属于两个目标。 I would keep on getting the error TestClassOne
not recognized when the TestClassOne
file was set to only one target but once I set the TestClassOne
file to both targets that error stopped appearing. 我会不断收到错误TestClassOne
时无法识别TestClassOne
文件设置为只有一个目标,但一旦我设定TestClassOne
文件的错误不再出现两个目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.