summaryrefslogtreecommitdiff
path: root/common/settings_nsuserdefaults.mm
blob: dfc601bddbaf9ce5b37c208206184dcc1a405ea6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#import <Foundation/Foundation.h>

#include "settings_nsuserdefaults.hpp"

using namespace mbgl;

Settings_NSUserDefaults::Settings_NSUserDefaults()
{
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{ @"longitude" : @(longitude),
                                                               @"latitude"  : @(latitude),
                                                               @"zoom"      : @(zoom),
                                                               @"bearing"   : @(bearing),
                                                               @"debug"     : @(debug) }];
    load();
}

void Settings_NSUserDefaults::load()
{
    NSDictionary *settings = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];

    longitude = [settings[@"longitude"] doubleValue];
    latitude  = [settings[@"latitude"]  doubleValue];
    zoom      = [settings[@"zoom"]      doubleValue];
    bearing   = [settings[@"bearing"]   doubleValue];
    debug     = [settings[@"debug"]     boolValue];
}

void Settings_NSUserDefaults::save()
{
    [[NSUserDefaults standardUserDefaults] setValuesForKeysWithDictionary:@{ @"longitude" : @(longitude),
                                                                             @"latitude"  : @(latitude),
                                                                             @"zoom"      : @(zoom),
                                                                             @"bearing"   : @(bearing),
                                                                             @"debug"     : @(debug) }];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

void Settings_NSUserDefaults::clear()
{
    [NSUserDefaults resetStandardUserDefaults];
}