gpt4 book ai didi

xcode - 防止接口(interface)名称在 OSX bundle 中公开

转载 作者:行者123 更新时间:2023-12-03 17:18:33 26 4
gpt4 key购买 nike

我有一组用 Cocoa 用 C++ 编写的 OSX 插件包(不使用界面生成器等),并且所有插件都使用相同的自定义 @interface 类作为其内部框架的一部分(它继承自 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.

我认为这只是一个警告,因为我的插件似乎在我所看到的所有情况下都能正常工作。我怀疑这个类被导出为公共(public)符号?然而,我希望这条消息消失:)

是否有一些我可以调整的 XCode 编译器设置,或者我可以添加一些额外的代码到自定义类以防止它被导出(如果这是原因的话)?我是 XCode/OSX 编码菜鸟,如果我错过了一些明显的东西,我很抱歉。

最佳答案

Objective-C 运行时正在尝试将同一个类 C_CustomView 加载到一个命名空间中。

命名 Objective-C 类的标准方式使用前缀: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.”

前缀用于防止这种冲突。

我的建议是将重用的类提取到自己的包/框架中,并在需要的地方导入该框架。

此外,根据引用,上面的类在命名类时不应使用下划线。前缀 + CamelCase 是 Objective-C 的规范。

PS:不确定 Swift 详细信息,但不需要前缀(假设它不共享命名空间)

关于xcode - 防止接口(interface)名称在 OSX bundle 中公开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57876091/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com