我目前正在尝试使用Swift 2.3创建自己的自定义iOS框架。我有一个用Obj-C编写的测试iOS应用,它嵌入+指向自定义框架的链接。

该框架有多个类,其中两个类似于以下类:

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类没有出现任何问题。尽管在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


尝试使用Constants类

NSLog(@"%@", [Constants CONST_VALUE1]);


导致此错误消息

Use of undeclared identifier 'Constants'


有人知道我会做错什么吗?

最佳答案

经过一番尝试和错误之后,我通过将.framework直接放入测试应用程序文件夹中解决了该问题。

关于ios - iOS框架-使用未声明的标识符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41234827/

10-10 23:24
查看更多