Xcode 7 自动生成初始化、getter 和 setter?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34715931/
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
Xcode 7 auto generate initialization, getter and setter?
提问by Lê Khánh Vinh
Hi I used to develop android app with android studio. I now building my app for IOS using Xcode 7. Is there any way or any framework that do the initialization
, getter
and setter
, parcelable
for model class
(like android studio
have automatic generate). Can Xcode
do the same and how to do that automatically? (just declare the variable and auto generate initialization
, getter
, setter
...)
嗨,我曾经用 android studio 开发 android 应用程序。我现在使用 Xcode 7 为 IOS 构建我的应用程序。有什么方法或任何框架可以为模型执行initialization
,getter
和setter
,parcelable
模型class
(例如android studio
自动生成)。可以Xcode
做同样的事情以及如何自动做到这一点?(只需声明变量并自动生成initialization
, getter
, setter
...)
采纳答案by dasdom
The compiler provides basic getter and setter according to the property declaration. If those don't fit your needs, you have to write them yourself.
编译器根据属性声明提供基本的 getter 和 setter。如果这些不符合您的需求,您必须自己编写它们。
Let's say you have this property:
假设你有这个属性:
property (strong, nonatomic) NSString *myValue;
The setter has to have this signature:
setter 必须有这个签名:
- (void)setMyValue(value: String) {
// some stuff
_myValue = value;
}
The getter has to have this signature:
getter 必须具有以下签名:
- (NSString *)myValue {
// some other stuff
return _myValue;
}