nicklockwood / FastCoding

A faster and more flexible binary file format replacement for NSCoding, Property Lists and JSON

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception rasied if modified the class's property

smalllixin opened this issue · comments

commented

Hi nick,
I am trying to adopt fastcoding lib. I found if the class property deleted or renamed will get a entire uninitialized object.
The reason I found setValue to a non existed property will raise an exception:

    for (__unsafe_unretained NSString *key in definition->_propertyKeys)
    {
            [object setValue:FCReadObject(decoder) forKey:key];
    }

The quick fix is add a try-catch to prevent the exception.

    for (__unsafe_unretained NSString *key in definition->_propertyKeys)
    {
        @try {
            [object setValue:FCReadObject(decoder) forKey:key];
        }
        @catch (NSException *exception) {

        }
    }

However if there is another better solution?

You could override setValue:forUndefinedKey: on your class and have it do nothing instead of crashing.

commented

Wow, this feels better. Thank u.