xcode iOS中的属性和合成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5719537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:51:16  来源:igfitidea点击:

Property and synthesize in iOS

objective-cxcodeiospropertiessynthesizer

提问by cyclingIsBetter

Possible Duplicate:
@property @synthesize

可能重复:
@property @synthesize

When must I use property and synthesize for an element as NSArray, NSSTring....or IBOutelt as UIButton or UITextFiled?

我什么时候必须使用属性并将元素合成为 NSArray、NSSTring....或 IBOutetlt 作为 UIButton 或 UITextFiled?

回答by voidzm

A property is used mainly when other objects need to change or access the ivars in your object. Without manually defining getters and setters, or using @property, other objects can't see or change the ivars. Properties are also often used for convenience of memory management, assisting you in preventing memory leaks.

属性主要在其他对象需要更改或访问您对象中的 ivars 时使用。如果不手动定义 getter 和 setter,或使用 @property,其他对象将无法看到或更改 ivars。属性也经常用于方便内存管理,帮助您防止内存泄漏。