【发布时间】:2011-05-01 00:54:02
【问题描述】:
我目前正在开发一个严重依赖于检索网络内容的应用。我有一系列 NSObject 类,它们代表我以 JSON 格式检索的内容。我还有代表我的核心数据模型的 NSManagedObject 类,它们几乎相同。
下面是我用来保存网页内容的 NSObject 类的示例:
@interface MovieRecord : NSObject {
NSString *movieTitle;
NSDecimalNumber *movieId;
NSString *movieRating;
NSString *movieDescription;
NSDate *movieReleaseDate;
NSMutableArray *movieVideos; // collection of class videoRecord
NSMutableArray *actors;
UIImage *movieImage;
NSURL *movieImageURL;
}
这是我的 NSManagedObject 类的示例:
@interface Movie : NSManagedObject
{
}
@property (nonatomic, retain) NSNumber * id;
@property (nonatomic, retain) NSString * description;
@property (nonatomic, retain) id image;
@property (nonatomic, retain) NSString * rating;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSDate * releaseDate;
@property (nonatomic, retain) NSString * imageURL;
@property (nonatomic, retain) NSSet* actors;
@end
在此示例中,用户将浏览大量电影,但他们并不总是将电影保存到持久存储中。这是我首先将信息存储到单独的类中的主要原因,然后如果他们决定保存它,我将填充 NSManaged 对象类并保存。 NSObject 类在用户深入到详细视图之前不会被完全填充(最初只设置了movieTitle 和movieID)。
我想我的问题是让这些类分开是否有意义?有没有更好的设计方法,我只是没有看到?我应该坚持使用 NSDictionary 来填充我的表格视图(NSDictionary 是从 JSON 数据填充的)吗?
【问题讨论】:
标签: iphone uitableview core-data nsdictionary nsobject