开发者

iphone: use Entity object created from Core Data?

I currently have a Video object created via Core Data defined as:

Video .h

#import <CoreData/CoreData.h>


@interface Video :  NSManagedObject  
{
}

@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSString * urlImage;
@property (nonatomic, retain) NSString * description;
@property (nonatomic, retain) NSString * urlString;

@end

and Video.m:

#import "Video.h"


@implementation Video 

@dynamic title;
@dynamic urlImage;
@dynamic开发者_Go百科 description;
@dynamic urlString;

@end

I need my app to create an NSMutableArray of these Video objects (off an XML stream) and display them to the user.

However, the Video should ONLY be persisted IF the user clicks 'Add to favorites'.

In the parsing method, I tried to create a Video object, and assign it the respective attributes. However, xCode would fail with this error (during video.title = xmlstream.title):

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Video setTitle:]: unrecognized selector sent to instance 0x70720d0'

Can someone please tell me how I can fix this to use the Video object regularly?


You should use @synthesize instead of @dynamic. When using @synthesize the getter (-propertyName) and setter (-setPropertyName:(id)newPropertyName) methods are automatically implemented, when using @dynamic, you have to do so yourself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜