Xcode4 自动生成 @property 声明及其相关内容

发布于 2024-10-31 05:59:01 字数 336 浏览 0 评论 0原文

当我使用 Xcode 3 时,我使用在网上找到的 perl 脚本对其进行了配置,该脚本允许我自动生成新实例变量的 @property、@synthesize 和 dealloc 代码。不过 Xcode 4 没有该用户脚本菜单。

有没有办法为 Xcode 4 插入这些类型的用户脚本,或者 Xcode 4 是否有自动生成这些内容的新功能? (我已经看过了,但找不到)。

我不是在谈论链接到 IBOutlets。我知道我可以从 xib 中拖动,它将为 IBOutlet 创建所有正确的内容,但我正在寻找能为任何实例变量创建 @property、@synthesize 和 dealloc 代码的东西。

谢谢, 肯尼

When I was using Xcode 3 I had configured it with a perl script I found on the web that allowed me to automatically generate the @property, @synthesize and dealloc code for new instance variables. Xcode 4 doesn't have that User Scripts menu though.

Is there a way to plug in these kinds of User Scripts for Xcode 4 or does Xcode 4 have a new feature that generates that stuff automatically? (I've looked and can't find one though).

I'm not talking about linking to IBOutlets. I know that I can drag from a xib and it will create all of the right stuff for IBOutlets, but I'm looking for something that will create @property, @synthesize and dealloc code for any instance variable.

Thanks,
Kenny

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

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

发布评论

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

评论(4

最美不过初阳 2024-11-07 05:59:01

我强烈(而且我不能充分强调这一点)建议该应用程序:

Accessorizer

这是迄今为止我发现的编写 Objective-C 和 Objective-C 2.0 代码最有用的应用程序。最初是在 ObjC2.0 之前编写的,它为您创建了 ivar getter 和 setter。多年来它一直在不断发展。现在它可以处理属性、容器类、键值编码、KVO。

它适合您的风格:您将括号放在哪一行,如何缩进,如何注释?它还作为服务安装,因此您可以从 XCode 调用它、复制到剪贴板并直接粘贴回 XCode。

我不是作者,我不会因为插入这个而得到任何东西。不过,我已经向我工作过的每个 Mac 团队介绍了它的用法,并且让每个 Obj-C 程序员在第一次使用时都转向它。

它有一个演示期。绝对至少尝试一下,看看它是否能解决您的问题。

I would strongly (and I can't emphasize this enough) suggest the application:

Accessorizer

This is by far the most useful application for writing objective-C and objective-C 2.0 code that I have found. Originally written in the pre ObjC2.0 days, it created ivar getters and setters for you. Over the years it just keeps evolving. Now it does properties, container classes, key value encoding, KVO.

It tailors to your style: What line do you put brackets on, how do you indent, how do you comment? It also installs as a service so you can call it up from XCode, copy to the clipboard and paste right back into XCode.

I am not the author, I get nothing for plugging this. However, I have introduced its usage to every Mac team I've worked on and have converted every Obj-C programmer to it on first use.

It's got a demo period. Definitely at least try it out and see if it solves your issue.

网白 2024-11-07 05:59:01

我设法让上面提到的 Xcode 3 perl 脚本在 Xcode 4 下工作作为一种行为。

我把它放在github上了。 https://bitly.com/HXHiij

希望有所帮助。

I managed to get the Xcode 3 perl script mentioned above working under Xcode 4 as a behaviour.

I put it up on github. https://bitly.com/HXHiij

Hope that helps.

一张白纸 2024-11-07 05:59:01

我还没有测试过其中任何一个,但两者都声称支持 Xcode 4:

  1. https://github.com/CraigWilliams /property_synthesize_dealloc
  2. https://public.me.com/dhoerl (导航到 Xcode/PropertyMaster )

I haven't tested either of these yet, but both claim to support Xcode 4:

  1. https://github.com/CraigWilliams/property_synthesize_dealloc
  2. https://public.me.com/dhoerl (Navigate to Xcode/PropertyMaster)
澜川若宁 2024-11-07 05:59:01

我也想念与属性相关的脚本,但我找到了解决方法。如其他地方所述,XCode 4 将自动为通过 IB 连接的 IBoutlet 生成属性/合成/释放代码。

因此,我的项目中有一个名为 Property_Hack.XIB 的虚拟 XIB,其中包含一些 UILabels,每当我需要类的新属性时,我都会转到 Property_Hack,更改所有者,并将标签“连接”到文件。您所要做的就是输入您想要的 ivar 的名称,XCode 会将 @property 语句添加到 .h 中,并在 .m 中添加 @synthesize 和 dealloc 代码。然后我修改 .h (删除 IBoutlet 关键字,并将 UILabel 更改为您想要的数据类型)。

虽然相当黑客化,而且远非完美,但与手动修改这两个文件相比,它仍然可以节省时间。由于 NSIntegers 和 BOOL 不需要 dealloc 代码,并且是分配而不是保留,所以我通常手动设置它们而不是使用这种方法。 NSStrings 是否应该复制或保留是一个论点,我不会在这里重复:-)

I also miss the property related scripts, but I have found a workaround. As noted elsewhere, XCode 4 will automatically generate the property/synthesize/dealloc code for IBoutlets that are hooked up through IB.

So I have a dummy XIB in my project called Property_Hack.XIB with some UILabels, and whenever I need a new property for a class I go to Property_Hack, change the owner, and "connect" a label to the file. All you have to do is enter the name of the ivar you want, and XCode will add the @property statement to the .h, and in the .m it will add the @synthesize and dealloc code. Then I modify the .h (delete IBoutlet keyword, and change UILabel to the datatype you want).

Rather hackish and far from perfect, but it is still a time saver compared to the manual effort of modifying both files. Since NSIntegers and BOOLs do not need dealloc code, and are assign instead of retain, I usually set them up manually instead of using this approach. Whether or not NSStrings should be copy or retain is an argument I will not rehash here :-)

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