rizzes
rizzes

Reputation: 1542

iOS - Set Derived Property

I have the following derived property:

SongWrapper.h

@property (nonatomic, strong) NSString *title;

SongWrapper.m

- (NSString *)title;
{
    return self.songDocument.songAttributes.title;
}

I tried to set it like this:

self.songViewController.songWrapper.title = titleTextField.text;

Why doesn't this work and what are the best practices for setting a derived property?

Upvotes: 0

Views: 137

Answers (1)

nprd
nprd

Reputation: 1942

You have to defined getter but not setter. You need to define setter as well.

//Getter
- (NSString *)title;
{
    return self.songDocument.songAttributes.title;
}

//Setter
- (void)setTitle:(NSString *)title;
{
    self.songDocument.songAttributes.title = title;
}

Upvotes: 1

Related Questions