Search code examples
xcodegettergetter-setter

Xcode 7 auto generate initialization, getter and setter?


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...)


Solution

  • 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.

    Let's say you have this property:

    property (strong, nonatomic) NSString *myValue;
    

    The setter has to have this signature:

    - (void)setMyValue(value: String) {
        // some stuff
        _myValue = value;
    }
    

    The getter has to have this signature:

    - (NSString *)myValue {
        // some other stuff
        return _myValue;
    }