views:

20

answers:

1

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 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?

+1  A: 

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.

Douwe Maan
... so if i replace @dynamic by @synthesize.. would that cause a problem for core data?
dpigera
Whoops, I hadn't noticed you were talking about a `NSManagedObject` subclass... In that case `@dynamic` should just work... Are you sure you have connected the entity to the class correctly? And you're creating the managed object correctly?
Douwe Maan
Yep. I want to be able to use the Video object outside of NSMangedObject though. Is that possible?
dpigera
No, the object's bound to the `NSManagedObject`, you can't `alloc` it like you're used to with other objects. (Sure, you *can*, but as you can see, it doesn't work). The only way to create a new `Video` object is to insert it into the `NSManagedObjectContext`, but that way, of course, it's in the data store, it's not a stand-alone object.
Douwe Maan