应该仍然使用@synthesize吗? [英] Should @synthesize be used still?

查看:90
本文介绍了应该仍然使用@synthesize吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道,即使Xcode自动将@synthesize用于属性,也仅仅是因为它已经做了这么长时间了,所以还是应该使用@synthesize吗?还是这意味着我们都可以停止使用@synthesize(除非您有理由为其实例变量指定其他名称)?

I'm just wondering if @synthesize should still be used even though Xcode does it automatically for properties, simply because it's been done that way for so long? Or does this mean we can all stop using @synthesize (unless you have a reason to give its instance variable a different name)?

我只是想确保从专业的角度来看我符合良好的编码习惯.

I just want to make sure that from a professional standpoint I'm conforming to good coding practice.

推荐答案

我个人不再将合成仅用于新开发 ,除非需要(请参阅下面的lnafziger的评论).原因是因为我当前正在为iOS 6开发,它需要新版本的Xcode,该版本具有在编译时自动包含@synthesize的功能.如果我要使用旧代码执行此操作,则我的组织中可能仍然有人在使用旧版本的Xcode(即4.2版),这会对他们造成问题.

I personally no longer use synthesize for new development only unless required (see lnafziger's comment below). The reason is because I currently develop for iOS 6, which requires a new version of Xcode, which has the capabilities of auto-including the @synthesize during compile time. If I were to do this with old code, there may still be someone in my organization that is using an old version of Xcode (i.e version 4.2) where this would cause problems for them.

因此,根据您是否仍然需要与旧版本的Xcode兼容,此答案将有所不同.但是,如果您只需要使用新版本的Xcode,则最好不要声明@synthesize.

So depending on if you still need to be compatible with the older versions of Xcode, this answer will vary. But if you only need to work with new versions of Xcode, you should be fine not declaring @synthesize.

这篇关于应该仍然使用@synthesize吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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