iOS 框架 - 使用未声明的标识符

标签 ios objective-c swift frameworks

我目前正在尝试使用 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 header 中引用了 Constants 类,但似乎找不到它:

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 框架 - 使用未声明的标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41234827/

相关文章:

ios - 在我的 iOS 应用程序中访问设备的所有照片

ios - Code=-1005 "网络连接丢失

ios - 如何在 iOS 中安全地保存字符串?

iphone - 处理工厂方法中的内存泄漏

objective-c - 带有 NSFetchedResultsController 和背景上下文的 UIManagedDocument

android - 通过基础设施 WiFi 或对等 Wifi 网络将音频从 iPhone 实时流式传输到 Android

iphone - 在 Objective-C 中分配/初始化实例变量的正确方法?

Swift 如何向 OBD2 设备发送 AT 命令?

swift - 将新的 ViewController 嵌入到现有的 UITabBarController 中?

swift - 快速保存 NSManagedObjectContext 时出错