user1802143
user1802143

Reputation: 15672

iOS property with only setter method

My understanding of properties is that they just construct getter and setter methods. Is there a way to create a property that just has a setter method? My question is similar to this Write only property in Objective-C but it looks like the only solutions given are explicitly declaring and defining a setter method. Is that the only way or can it be done with properties?

Upvotes: 1

Views: 895

Answers (1)

JonahGabriel
JonahGabriel

Reputation: 3084

If you are asking if you can have IOS automatically synthesize a "write only" property, than no. However, you can explicitly set a getter method that returns nil.

Example:

@property(strong, nonatomic) NSString *myString;

-(NSString *)myString
{
    return nil;
}

Upvotes: 1

Related Questions