XCode 中将委托或协议的方法添加到 .m 文件的最有效方法是什么? [英] What is the most efficient way in XCode to add a delegate's or protocol's methods to the .m file?

查看:26
本文介绍了XCode 中将委托或协议的方法添加到 .m 文件的最有效方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在.Net 环境中实现一个接口(相当于Objective-C 中的一个协议)时,IDE 会自动将需要实现的属性和方法添加到类的文件中.是否存在会在 Xcode 环境中导致类似行为的设置?它会为代表做同样的事情吗?

When one implements an interface (equivalent to a protocol in Objective-C) in the .Net environment, the IDE automatically adds the properties and methods that need to be implemented to the class's file. Is there a setting that will result in a similar behavior in the Xcode environment? Will it do the same for a delegate?

此时,我发现自己正在从 Apple 的在线文档中复制/粘贴协议/委托的方法.

At this point, I find myself copying/pasting the protocol/delegate's methods from Apple's online documentation.

推荐答案

抱歉迟到了,我使用这个巧妙的技巧.

sorry for late comment, I use this neat trick.

例如,您的类名为MyClass",您希望它具有协议 NSTableDataSource.你要做的就是写

For example, your class is named "MyClass", you want it to have protocol NSTableDataSource. What you do is write

@interface MyClass : NSObject <NSTableDataSource> 
{ 
   ... usual stuff here ...
@end

然后,您右键单击 NSTableDataSource,单击跳转到定义"....然后您可以从那里复制它.

then, you right-click on NSTableDataSource, click on "Jump to definition".... and you can copy it from there.

如果你想让它成为 NSTableView 的委托,那么你只需将协议命名为 NSTableViewDelegate (这是一个实际的协议名称!),右键单击它,单击跳转到定义" - 你有它,你只需要忽略那些预处理器标记.

If you want it to be delegate of, let's say again, NSTableView, you just name the protocol NSTableViewDelegate (this is an actual protocol name!), right click on it, click on "Jump to definition" - and you have it there, you just have to ignore those preprocessor marks everywhere.

它可能不像 Java 接口和 NetBeans 那样简单,但速度也不会明显变慢.

It's maybe not as easy as with for example Java interfaces and NetBeans, but it's not significantly slower.

这篇关于XCode 中将委托或协议的方法添加到 .m 文件的最有效方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆