0
votes

I am not sure whether using transient attribute is the correct way for my situation. I am getting kind of feeds from server and stores in the core data. Am showing all these feeds in a TableView. There are many types of feeds, so cell layout and subviews vary with each feed. In some feeds, I need to set a temporary variable (BOOL and Integer. So NSNumber I know). The use case is, user should be able to enlarge and collapse some of the cells (A kind of "Read more.." link). So this state, I need to keep with each feed(NSManagedObject) object. This state will be there till app is running. It should not be saved to persistence storage because when user opens the app, all feed should be fresh.

I just added attribute with transient but it seems not working. I added 'NSNumber selected' attribute in entity as transient and added property and @dynamic in NSManagedObject file. I searched the forum and no solution is matching with mine. I tried with many sample stuffs but it really confusing..

Interface file is,

@interface FeedItemBase : NSManagedObject {
@private
}
@property (nonatomic, retain) NSDate * timestamp;
@property (nonatomic, retain) NSString * type;
@property (nonatomic, retain) NSNumber * premium;
@property (nonatomic, retain) NSNumber *selected; //This is what I added

@end

Implementation file is,

@implementation FeedItemBase
@dynamic timestamp;
@dynamic type;
@dynamic premium;
@dynamic selected; //This is what I added

@end

So please help me on this.

1

1 Answers

1
votes

If you don't need to query it, just add a regular BOOL to your managed object subclass.

@property (nonatomic, assign) BOOL selected; //This is what I added

and in your .m file

@synthesized selected = _selected;

Transient properties in core data have so many odd edge cases; in my experience, I avoid them if I can.