Objective C 中的第一个参数名称?

发布于 2024-12-25 08:31:28 字数 399 浏览 3 评论 0原文

我有一个方法:

- (void)pan:(double)lat 经度: (double) lon{...}

当我调用它时,Xcode 显示如下:

[自动平移:(双)经度:(双)]

是否可以以某种方式设置第一个参数,例如第二个 (longitude),Xcode 可以显示如下这:

[自动平移:纬度:(double) 经度:(double)]

调用时看不到第一个参数的名称,这对我来说很烦人。是我的错还是不可能?

I have a method:

- (void)pan:(double)lat longitude: (double) lon{...}

When I call it Xcode shows to like this:

[self pan:(double) longitude:(double)]

Isn't it possible to set first parameter somehow, like the second (longitude), that Xcode could show like this:

[self pan: latitude:(double) longitude:(double)]

It is very annoying for me that I can not see the name of the first parameter when calling. Is it my fault or it is impossible?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如痴如狂 2025-01-01 08:31:28

执行您要求的操作的正常方法是声明您的方法,如下所示:

-(void)panLatitude:(double)lat longitude:(double)lon;

也就是说,在开头包含第一个参数的标签和方法名称。你会这样使用它:

[self panLatitude:x longitude:y];

The normal way to do what you're asking is to declare your method like:

-(void)panLatitude:(double)lat longitude:(double)lon;

That is, include the label for the first argument with the method name at the beginning. You'd use it like:

[self panLatitude:x longitude:y];
℡寂寞咖啡 2025-01-01 08:31:28

您只需以不同的方式命名该方法即可。

- (void)panToLatitude: (double)lat longitude: (double)lon;

Objective-C 实际上没有命名参数。该方法的名称是(在您的示例中,不是我上面的版本)-pan:longitude: 并且该语言使用中缀表示法来传递参数。

You just need to name the method differently.

- (void)panToLatitude: (double)lat longitude: (double)lon;

Objective-C doesn't actually have named parameters. The name of the method is (in your example, not my version above) -pan:longitude: and the language uses infix notation to pass the arguments.

渡你暖光 2025-01-01 08:31:28

请记住,objective-c 的作用是向对象发送消息 - 消息就是参数。因此消息的第一部分通常包含动词和第一个数据。它应该很容易阅读。

不要将方法名称视为“pan”。在 C# 和 Java 中,方法名称为 Pan,参数为经度和纬度。你的方法应该是这样的。

- (void) panToLatitude:longitude:

该字符串是您的函数(消息)名称。将其视为发送一条字典形式的消息,第一项包含动词。我也有 C 语言背景,所以这是一种不同的思维方式。

Remember that objective-c is about sending messages to objects - the message is the args. So the first part of the message often contains the verb and first piece of data. It should read easily.

Do not think of the method name as "pan". In C# and Java the method name would be Pan and the args would be longitude and latitude. Your method should be something like.

- (void) panToLatitude:longitude:

That string is your function (message) name. Think of it as send a message that is a dictionary and the first item contains the verb. I come from C langs background as well so it's a different way of thinking.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文