【发布时间】:2016-12-20 04:16:54
【问题描述】:
我目前正在尝试使用 Swift 2.3 创建自己的自定义 iOS 框架。我有一个测试 iOS 应用程序,用 Obj-C 编写,它嵌入了自定义框架的 + 链接。
该框架有多个类,其中两个类似于以下:
public class Constants: NSObject
{
private static let sharedInstance = Constants()
override init() { }
public static let CONST_VALUE1 = "somevalue1"
public static let CONST_VALUE2 = "somevalue2"
}
和
public class RandomUtils: NSObject
{
private static let sharedInstance = RandomUtils()
override init() { }
public static func randomFunction(someValue: String) -> String?
{
return someValue
}
}
在测试应用程序中看到和使用 RandomUtils 类没有任何问题。然而,似乎找不到 Constants 类,尽管它在 SDK-Swift.h 标头中被引用:
SWIFT_CLASS("_TtC6sdk9Constants")
@interface Constants : NSObject
+ (NSString * _Nonnull)CONST_VALUE1;
+ (NSString * _Nonnull)CONST_VALUE2;
@end
SWIFT_CLASS("_TtC6sdk16RandomUtils")
@interface RandomUtils : NSObject
+ (NSString * _Nonnull)randomFunction:(NSString * _Nonnull)someValue;
@end
在我的测试应用程序中,我将框架伞头文件导入到我的 ViewController 的头文件中:
#import <UIKit/UIKit.h>
#import <SDK/SDK-Swift.h>
@interface TestVC : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *txtValue1;
@end
尝试使用常量类
NSLog(@"%@", [Constants CONST_VALUE1]);
导致此错误消息
Use of undeclared identifier 'Constants'
有人知道我做错了什么吗?
【问题讨论】:
标签: ios objective-c swift frameworks