[英]iOS - Set Derived Property
我具有以下派生屬性:
SongWrapper.h
@property (nonatomic, strong) NSString *title;
SongWrapper.m
- (NSString *)title;
{
return self.songDocument.songAttributes.title;
}
我試圖這樣設置:
self.songViewController.songWrapper.title = titleTextField.text;
為什么這不起作用?設置派生屬性的最佳實踐是什么?
您必須定義getter而不是setter。 您還需要定義setter。
//Getter
- (NSString *)title;
{
return self.songDocument.songAttributes.title;
}
//Setter
- (void)setTitle:(NSString *)title;
{
self.songDocument.songAttributes.title = title;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.