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

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

问题描述

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



在这一点上,我发现自己从Apple的在线文档复制/粘贴协议/委托的方法。

解决方案

对不起的评论,
我使用这个整洁的技巧。



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

  @interface MyClass:NSObject< NSTableDataSource> 
{
...通常的东西在这里...
@end

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



如果你想要代理,再说一遍NSTableView,你只需命名协议NSTableViewDelegate(这是一个实际的协议名称!),右键点击它,点击跳转到定义 - 你有它在那里,你只需要忽略那些预处理标记到处。



它可能不像Java接口和NetBeans那么简单,但是这并不是很慢。


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?

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.

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

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

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.

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天全站免登陆