Search code examples
iosxcodecocoa-touchcore-datainappsettingskit

InAppSettingsKit and Core Data


I'm currently implementing a custom IASKSettingsStore for the use of core data. You can see the code below. The problem is that the storage of the values gets extremely slow. For example when I type something in a text field, i know that IASKAppSettingsViewController stores every change, but I figured out that even one single change is stored very slow. How can I make this work faster?

What do I oversee? Thanks in advance.

So far the custom IASKSettingsStore looks like this:

@implementation GPSettingsStoreCoreData

@synthesize managedObject = _managedObject;

- (id)initWithManagedObject:(NSManagedObject *)managedObject {
    self = [super init];
    if( self ) {
        _managedObject = managedObject;
    }
    return self;
}

- (id)init
{
    if (self = [super init]) {
        _managedObject = nil;
    }
    return self;
}

- (void)setBool:(BOOL)value forKey:(NSString*)key {
    [self.managedObject setValue:[NSNumber numberWithBool:value] forKey:key];
}

- (void)setFloat:(float)value forKey:(NSString*)key {
    [self.managedObject setValue:[NSNumber numberWithFloat:value] forKey:key];
}

- (void)setDouble:(double)value forKey:(NSString*)key {
    [self.managedObject setValue:[NSNumber numberWithDouble:value] forKey:key];
}

- (void)setInteger:(int)value forKey:(NSString*)key {
    [self.managedObject setValue:[NSNumber numberWithInt:value] forKey:key];
}

- (void)setObject:(id)value forKey:(NSString*)key {
    [self.managedObject setValue:value forKey:key];
}

- (BOOL)boolForKey:(NSString*)key {
    return [[self.managedObject valueForKey:key] boolValue];
}

- (float)floatForKey:(NSString*)key {
    return [[self.managedObject valueForKey:key] floatValue];
}

- (double)doubleForKey:(NSString*)key {
    return [[self.managedObject valueForKey:key] doubleValue];
}

- (int)integerForKey:(NSString*)key {
    return [[self.managedObject valueForKey:key] intValue];
}

- (id)objectForKey:(NSString*)key {
    return [self.managedObject valueForKey:key];
}

@end

Solution

  • Well, finally I figured out myself where the problem is. Is has nothing to do with InAppSettingsKit. I present the InAppSettingsKit controller as a modal view controller from a view controller with a NSFetchedResultsController. So every change I make in the settings controller sends a call to the delegate of the NSFetchedResultsController. As a result, the whole table view is being unnecessarily reloaded. I solved it using a child managed object object context for the modal view controller. I found a very helpful article on that topic: http://www.cocoanetics.com/2012/07/multi-context-coredata/

    And the custom IASKSettingsStore for Core Data I posted above works pretty well so far, so you can implement it into your own project if you want.