karelia / KSExtensibleManagedObject

KSExtensibleManagedObject
http://www.mikeabdullah.net/ksextensiblemanagedobject.html
Other
26 stars 1 forks source link

Exception `NSInconsistentArchiveException` doesn't exist on iOS #3

Open adib opened 10 years ago

adib commented 10 years ago

The method primitiveExtensibleProperties refers to an exception named NSInconsistentArchiveException which doesn't seem to exist on iOS SDK as of 7.1 – I recommend to use the string value instead on iOS, like so:

- (NSMutableDictionary *)primitiveExtensibleProperties;
{
    // Fault in the properties on-demand
    if (!_extensibleProperties)
    {
        @try {
            _extensibleProperties = [[NSMutableDictionary alloc] initWithDictionary:self.archivedExtensibleProperties];
            NSAssert(_extensibleProperties, @"-initWithDictionary: let me down");
        }
        @catch (NSException *exception) {
            // Catch and handle the exception by resetting properties to be empty. But then rethrow
            // the exception since the reset is only desirable if client code catches the exception
            // itself and chooses to proceed.
#if TARGET_OS_IPHONE
            if ([exception.name isEqualToString:@"NSInconsistentArchiveException"]) {
#else
            if ([exception.name isEqualToString:NSInconsistentArchiveException]) {
#endif // TARGET_OS_IPHONE
                NSLog(@"Resetting extensible properties after failure to unarchive: %@", self);
                _extensibleProperties = [[NSMutableDictionary alloc] init];
            }

            @throw exception;
        }
    }

    return _extensibleProperties;
}
mikeabdullah commented 10 years ago

Do you have any evidence that exception ever happens on iOS? My inclination is to let it throw until there's a concrete case to worry about.

adib commented 10 years ago

No evidence. Maybe just #if it out on iOS?

Thanks

Sasmito Adibowo http://basilsalad.com +65 8135 8937

On 6 Aug, 2014, at 17:18, Mike Abdullah notifications@github.com wrote:

Do you have any evidence that exception ever happens on iOS? My inclination is to let it throw until there's a concrete case to worry about.

— Reply to this email directly or view it on GitHub.

mikeabdullah commented 10 years ago

Agreed, and changed in commit 149dae1694074e60548b5730ea1176f9b39c9fb8