防止接口名称进入 OSX 包中的 public
Prevent interface name from going public in OSX bundle
我有一组 OSX 用 C++ 编写的插件包 Cocoa (不使用界面生成器和所有这些),并且都使用相同的自定义 @interface
class 作为其内部框架的一部分(它继承自 NSView)。很简单;
@interface C_CustomView : NSView
- (BOOL)performKeyEquivalent:(NSEvent*)event;
@end
@implementation C_CustomView
- (BOOL)performKeyEquivalent:(NSEvent*)event {
[super keyDown:event];
return YES;
}
@end
但是,当主机应用程序同时加载我的多个插件时,我在 XCode 日志中收到了同样多的警告,指出:
objc[4144]: Class C_CustomView is implemented in both <bundle 1's
path> and <bundle 2's path>. One of the two will be used. Which one is
undefined.
我认为这只是一个警告,因为就我所见,我的插件似乎工作正常。我怀疑这个 class 被导出为 public 符号?但是,我希望这条消息消失:)
是否有一些我可以调整的 XCode 编译器设置,或者我可以添加一些额外的代码到自定义 class 以防止它被导出,如果这是原因?我是一个 XCode/OSX 编码菜鸟,如果我错过了一些明显的东西,我很抱歉。
Objective-C 运行时正在尝试将相同的 class C_CustomView
加载到一个命名空间中。
标准命名方式 Objective-C classes 使用前缀:developer.apple.com
Prefixes are an important part of names in programmatic interfaces.
They differentiate functional areas of software. Usually this software
comes packaged in a framework or (as is the case of Foundation and
Application Kit) in closely related frameworks. Prefixes protect
against collisions between symbols defined by third-party developers
and those defined by Apple (as well as between symbols in Apple’s own
frameworks).
A prefix has a prescribed format. It consists of two or three
uppercase letters and does not use underscores or “sub prefixes.”
前缀用于防止这种冲突。
我的建议是提取重用的 class 以拥有 bundle/framework 并在需要的地方导入此框架。
此外,根据引文,在命名 classes 时不应使用下划线。前缀 + CamelCase 是 Objective-C.
的规范
PS:不确定 Swift 细节,但那里不需要前缀(假设它不共享命名空间)
我有一组 OSX 用 C++ 编写的插件包 Cocoa (不使用界面生成器和所有这些),并且都使用相同的自定义 @interface
class 作为其内部框架的一部分(它继承自 NSView)。很简单;
@interface C_CustomView : NSView
- (BOOL)performKeyEquivalent:(NSEvent*)event;
@end
@implementation C_CustomView
- (BOOL)performKeyEquivalent:(NSEvent*)event {
[super keyDown:event];
return YES;
}
@end
但是,当主机应用程序同时加载我的多个插件时,我在 XCode 日志中收到了同样多的警告,指出:
objc[4144]: Class C_CustomView is implemented in both <bundle 1's path> and <bundle 2's path>. One of the two will be used. Which one is undefined.
我认为这只是一个警告,因为就我所见,我的插件似乎工作正常。我怀疑这个 class 被导出为 public 符号?但是,我希望这条消息消失:)
是否有一些我可以调整的 XCode 编译器设置,或者我可以添加一些额外的代码到自定义 class 以防止它被导出,如果这是原因?我是一个 XCode/OSX 编码菜鸟,如果我错过了一些明显的东西,我很抱歉。
Objective-C 运行时正在尝试将相同的 class C_CustomView
加载到一个命名空间中。
标准命名方式 Objective-C classes 使用前缀:developer.apple.com
Prefixes are an important part of names in programmatic interfaces. They differentiate functional areas of software. Usually this software comes packaged in a framework or (as is the case of Foundation and Application Kit) in closely related frameworks. Prefixes protect against collisions between symbols defined by third-party developers and those defined by Apple (as well as between symbols in Apple’s own frameworks).
A prefix has a prescribed format. It consists of two or three uppercase letters and does not use underscores or “sub prefixes.”
前缀用于防止这种冲突。
我的建议是提取重用的 class 以拥有 bundle/framework 并在需要的地方导入此框架。
此外,根据引文,在命名 classes 时不应使用下划线。前缀 + CamelCase 是 Objective-C.
的规范PS:不确定 Swift 细节,但那里不需要前缀(假设它不共享命名空间)