Reputation: 119
i want to store a custom object with a block in NSUserDefaults. I've already implement
- (void)encodeWithCoder:(NSCoder *)encoder and - (id)initWithCoder:(NSCoder *)decoder
is there a way to store myblock variable during this call ? something like this :
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeSomething:self->_myblock forKey:@"myblock"];
}
I've already tried to encodeObjectf and it does not seems to work... if someone already try this, i might appreciate your help :-)
Elendar.
Upvotes: 0
Views: 470
Reputation: 3520
I think its better to searlize data instead of blocks. Create some custom class and searlize your data and on the runtime you can always create the block utilizing that data. AFAIK blocks don't confirms to NSCoding (Correct me if I'm wrong here).
-MANNUpvotes: 0
Reputation: 6032
Seems that's not possible directly. You may do this indirectly, nice solution suggested here: Is there any way to serialize / unserialize an Objective-C block?
Upvotes: 1