GaetanJUVIN
GaetanJUVIN

Reputation: 119

How to store custom objects with blocks variable in NSUserDefaults

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

Answers (2)

MANN
MANN

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).

-MANN

Upvotes: 0

MANIAK_dobrii
MANIAK_dobrii

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

Related Questions