美文网首页iOS
iOS中@Synthesized现在还有啥用

iOS中@Synthesized现在还有啥用

作者: 码农二哥 | 来源:发表于2016-11-07 15:39 被阅读58次

Most Properties Are Backed by Instance Variables

You Can Customize Synthesized Instance Variable Names

As mentioned earlier, the default behavior for a writeable property is to use an instance variable called _propertyName.

If you wish to use a different name for the instance variable, you need to direct the compiler to synthesize the variable using the following syntax in your implementation:

@implementation YourClass
@synthesize propertyName = instanceVariableName;
...
@end

For example:

@synthesize firstName = ivar_firstName;

In this case, the property will still be called firstName, and be accessible through firstName and setFirstName: accessor methods or dot syntax, but it will be backed by an instance variable called ivar_firstName.

Important: If you use @synthesize without specifying an instance variable name, like this:

@synthesize firstName;
  • the instance variable will bear the same name as the property.
  • In this example, the instance variable will also be called firstName, without an underscore.

References

https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html#//apple_ref/doc/uid/TP40011210-CH5-SW2

相关文章

  • iOS中@Synthesized现在还有啥用

    Most Properties Are Backed by Instance Variables You Can ...

  • Swift Hashable 和 Equatable

    Hashable 和 Equatable Swift provides a synthesized impleme...

  • Property's synthesized getter fo

    Property's synthesized getter follows Cocoa naming conven...

  • 供佛供什么?

    “妈妈,咱们家现在还有红糖,坚果,甘蔗,砂糖橘等等,咱们明天用啥供佛呢?” “随你吧,你愿意供啥就供啥吧……” 3...

  • React Native 初探

    React Native是啥? 是一款用JavaScriptScript编写原生(Android,iOS)应用的框...

  • React Native 初探

    React Native是啥? 是一款用JavaScriptScript编写原生(Android,iOS)应用的框...

  • iOS显示web内容的三种方式

    iOS15中WKWebView新增的功能 UIWebView--iOS2+ 在iOS12以后已经被苹果弃用,建议用...

  • 自身剖析规划--20210926

    本人做ios开发五六年了,在现在的公司已经四年,舒适区呆久了,自己都不知道自己是啥鸟样了。 由于客观生活要求,还有...

  • UIDocumentPickerViewController使用

    一些老的初始化方法发现在iOS14已经弃用,例如 一些新的方法iOS14之后使用的发现在代码中根本索引不出来,例如...

  • 新图标「wallet」

    在WWDC发布会上,iOS9向全世界发布了。在iOS9中,出现了几个新图标,其中一个就是「wallet」,现在我用...

网友评论

    本文标题:iOS中@Synthesized现在还有啥用

    本文链接:https://www.haomeiwen.com/subject/eheouttx.html