Xcode 代码补全中类扩展中方法的可见性

发布于 2024-11-29 19:12:59 字数 1217 浏览 1 评论 0原文

我看到了一个类似的问题,解决了代码完成之间的差异Xcode 3.2 和 Xcode 4。我的问题涉及 Xcode (3.2) 的特定行为。

当我在类扩展中声明“私有”方法时,这些方法在代码完成列表中可见,而它们不应该在其中可见。

一个例子(AClass.m):

#import "AClass.h"

@interface AClass()
- (void)someMethod;
@end

@implementation AClass
//...
- (void)someMethod
{
    // do something here
}
//...
@end

当我将 AClass.h 导入到其他类并创建一个 AClass 实例时...

AClass *test = [[AClass alloc] init];

Xcode 的代码完成显示“私有”方法“someMethod”:

[test som     // Shows someMethod, though it shouldn't be visible here

此时,该方法是可见的,即使它不应该是,因为它在这里是未知的 - 它没有在头文件中定义。如果我在那时发送消息 [test someMethod] 并构建该东西,我会收到一条警告,该对象可能不会按预期响应。

它实际上确实做出了响应,但这是令人困惑的行为,尤其是对于其他想要使用我的类的人来说。

这也会影响@property / @synthesize,因为它们“只是替换方法”。我想通过属性访问我的所有私有 ivars,a) 具有同质代码,同时 b) 能够影响 ivars 的使用(如惰性实例化)。另一方面,所有私有内容对于使用我的类的任何人都不应该可见(在代码完成中),以便更轻松地使用它们。

有什么方法可以改变这种行为吗?

Xcode 3.2 中缺少上下文验证是代码完成显示这种不应该可见的方法的原因吗?< /em>

Xcode 4 中的行为是否有所不同(因为上下文验证)?

我仍然使用 Xcode 3.2,因为我想在切换和适应 Xcode 4 之前完成一个项目。

I saw a similar question addressing differences of the code completion between Xcode 3.2 and Xcode 4. My question addresses a specific behaviour of Xcode (3.2).

When I declare "private" methods in a class extension, these methods are visible in the code completion lists, where they shouldn't be visible.

An example (AClass.m):

#import "AClass.h"

@interface AClass()
- (void)someMethod;
@end

@implementation AClass
//...
- (void)someMethod
{
    // do something here
}
//...
@end

When I import AClass.h to some other class and create an AClass-instance...

AClass *test = [[AClass alloc] init];

Xcode's code-completion shows the "private" method "someMethod":

[test som     // Shows someMethod, though it shouldn't be visible here

At that point, this method is visible, even if it shouldn't be, because it's unknown here - it's not defined in the header-file. If I send the message [test someMethod] at that point and build the thing, I get a warning, that the object might not respond - as expected.

It actually does respond, but this is confusing behaviour, especially for someone else, who wants to use my class.

That affects @property / @synthesize as well, since they "just substitute methods". I want to access all of my private ivars by properties for a) having homogene code while b) being able to influence the use of ivars (like lazy instantiation). On the other hand all private stuff shouldn't be visible (in code completion) to anyone using my classes, to make it easier to use them.

Is there any way to change this behaviour?

Is the missing validation of context in Xcode 3.2 the reason, why code-completion shows this kind of methods, where they shouldn't be visible?

Is that behaviour different in Xcode 4 (because of context-validation)?

I still use Xcode 3.2, because I wanted to finish a project before switching and adapting myself to Xcode 4.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文