views:

157

answers:

1

How do I create a cache for a struct pointer object in Objective-C? Is there any third party component for caching objects as Java and .NET have?

I have the following struct:

typedef struct _news {
  references
  char *headline;
  char *story_url;
} news;

I have a double pointer for the above struct in an interface class. I would like to cache it for some time using Objective-C.

+1  A: 

Are you searching for something like this?

// save
NSMutableData *data = [[NSMutableData alloc] init];
[data appendBytes:&p length:sizeof(news)];

// read
struct news *begin = (struct news *)[data bytes];
catlan