我用PFObject以下子類:PFObject的子類化:重寫動態getter的正確方法是什麼?
//HEADER FILE
#import <Parse/Parse.h>
@interface ParseMenuItem : PFObject <PFSubclassing>
@property (nonatomic, strong) NSString * name;
@property (nonatomic, strong) NSString * menuItemDescription;
@property (nonatomic, strong) NSArray * menuPortions; //Some other PFObjects...
@property (nonatomic, strong) NSArray * categories; //NSStrings
//...
@end
//IMPLEMENTATION FILE
#import <Parse/PFObject+Subclass.h>
#import "ParseMenuItem.h"
@implementation ParseMenuItem
@dynamic name, menuItemDescription, menuPortions, categories;
+ (NSString*) parseClassName {
return @"MenuItem";
}
//...
@end
每次我嘗試訪問menuItem.categories
或menuItem.menuPortions
其中menuItem
是ParseMenuItem
類型的獲取對象,異常Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Key "categories"/"menuPortions" has no data. Call fetchIfNeeded before getting its value.'
提高。
如何自定義這些屬性的獲取方法,以便在需要時自動提取數據?
我不知道如何動態生成的getter看起來像,所以我不知道我必須寫什麼來取代他們一些自定義的。
有沒有辦法在我提供的那個中調用動態生成的一個?
對不起,但這不能回答我的問題。 'menuItemDescription'不是問題,我不想讓它異步。我想做一個阻止抓取。 –
好的,添加了一些東西。讓我知道? – Fosco
這不能被編譯。你的意思是'_categories'?但是後來我必須綜合這個屬性,我真的不知道會發生什麼,如果我綜合了一個屬性,應該動態添加...基本上我想知道getter的動態版本是什麼樣的,所以我可以使用我自己的版本,而不會失去解析提供的功能。 –