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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:24:55  来源:igfitidea点击:

Xcode 7 auto generate initialization, getter and setter?

xcodegettergetter-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, getterand setter, parcelablefor model class(like android studiohave automatic generate). Can Xcodedo 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,gettersetter,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;
}