我知道有很多其他的帖子都是关于这个问题的,但我唯一能找到的和我的(Objc Bridge)有相同背景的帖子是this...但这对我来说并不管用.
我有以下层次 struct :
// Dependency chain:
// AppTarget->Lib1
// Lib1->Lib2
AppTarget
Lib1
-- AppDelegate.swift
Lib2
-- ObjCppWrapperApple.mm (contains ObjCppWrapper ObjC class)
-- ObjCppWrapperIOS.mm (Contains a category named 'iOS' for the ObjCppWrapper ObjC class)
// Note: The bridging header is the same for Lib1 and Lib2. Both ObjCppWrapperApple.hpp and ObjCppWrapperIOS.hpp are included in the bridging header
ObjCppWrapperApple.hpp:
@interface ObjCppWrapper : NSObject
// Some methods
@end
ObjCppWrapperIOS.hpp:
#import "ObjCppWrapperApple.hpp"
@interface ObjCppWrapper (iOS)
+ (BOOL) PreInitialize NS_SWIFT_NAME (PreInitialize());
// Other methods
@end
ObjCppWrapperIOS.mm:
#import "ObjCppWrapperIOS.hpp"
@implementation ObjCppWrapper (iOS)
+ (BOOL) PreInitialize
{
// Some code
}
// Other methods
@end
从AppDelegate.swft中,我调用
ObjCppWrapper.PreInitialize()
而这在以下方面失败了
Thread 1: "+[ObjCppWrapper PreInitialize]: unrecognized selector sent to class"
而这只发生在tvOS上.它为iOS工作.
根据this stackoverflow post,类别和原来的班级应该在同一个目标.这是我的情况,但从Lib1中,我无法访问ObjCppWrapper类的iOS类别中的任何方法(在本例中为PreInitialize).我还将两个ObjCppWrapper类都移到了Lib1,即与AppDelegate.swft相同的目标,但应用程序仍然崩溃并出现错误.
不确定为什么找不到PreInitialize方法.而且只支持tvOS.