Latest 0.0.2
Homepage https://github.com/mysterioustrousers/MYSSharedSettings
License MIT
Platforms ios 6.0, osx 10.8, requires ARC
Dependencies MYSRuntime
Frameworks Foundation
Authors

Access local settings and settings shared via iCloud with properties.

Installation

Add this to your Podfile:

pod 'MYSSharedSettings'

Usage

  1. Subclass MYSSharedSettings.
  2. Define properties in .h file.
  3. Add @dynamic statement for each property in .m file.
  4. Set [YourSubclass sharedSettings].syncSettingsWithiCloud = YES; // (or NO) somewhere in your code.

Example

// CVSharedSettings.h

@interface CVSharedSettings : MYSSharedSettings
@property (nonatomic, assign) BOOL remindersEnabled;
@end

// CVSharedSettings.m
@implementation CVSharedSettings
@dynamic remindersEnabled;
@end

Then you read and set the settings properties like normal:

#import "CVSharedSettings.h"

[YourSubclass sharedSettings].syncSettingsWithiCloud = YES;

[CVSharedSettings sharedSettings].remindersEnabled = YES;

if ([CVSharedSettings sharedSettings].remindersEnabled) {
    // ... whatever happens when reminders are enabled
}

The same properties in your app running on other devices will now have the values you’ve set.

Providing Defaults

You can override the defaults method to provide defaults for NSUserDefaults:

- (NSDictionary *)defaults
{
    return @{
         @"remindersEnabled"                    : @YES,
         @"timezoneSupportEnabled"              : @NO,
         @"showDurationOnReadOnlyEvents"        : @NO,
         @"localRootTableViewMode"              : @(CVRootTableViewModeAgenda),
         @"hiddenEventCalendarIdentifiers"      : @[],
         @"customCalendarColors"                : @{},
         @"defaultEventAlarms"                  : @[@(MTDateConstantSecondsInMinute * 15)],
         @"defaultAllDayEventAlarms"            : @[@(MTDateConstantSecondsInHour * 6)],
         @"defaultEventReminder"                : @[@(MTDateConstantSecondsInMinute * 15)],
         @"defaultAllDayReminderAlarms"         : @[@(MTDateConstantSecondsInHour * 6)]
         };
}

Notifications

Listen for MYSSharedSettingsChangedNotification to be informed when remotely changed settings arrive.

Transforming Keys

Override - (NSString *)keyForPropertyName:(NSString *)propertyName to transform the property name into the string that will
be used as the key when storing the value in NSUserDefaults and NSUbiquitousKeyValueStore.

Excluding Properties From Sync

If you have iCloud syncing enabled but don’t want a certain property to be synced, prefix it with local and MYSSharedSettings will only
store it in NSUSerDefaults. (e.g. localViewMode)

Pushing Local Settings to iCloud

Call - (void)pushLocalToiCloud to overwrite any settings currently in iCloud with the local settings in NSUserDefaults.

Changelog

  • ChangedMYSSharedSettingsChangedNotification to fire both when ubiquity values change, but also local values. And the object
    is not an array of changed property keys.

Latest podspec

{
    "name": "MYSSharedSettings",
    "version": "0.0.2",
    "summary": "Access local settings and settings shared via iCloud with properties.",
    "description": "                   ### Instructionsn                   * Subclass MYSSharedSettings.n                   * Add properties.n                   * Declare the properties as @dynamic in @implementation.n                   * Now you can use it like so: `[YourSubclass sharedSettings].themeColor = [UIColor blackColor];`n                   * Turn on iCloud syncing with `[YourSubclass sharedSettings].syncSettingsWithiCloud = YES;` This will store the settings inn                   both `NSUserDefaults` and `NSUbiquitousKeyValueStore`. n",
    "homepage": "https://github.com/mysterioustrousers/MYSSharedSettings",
    "license": "MIT",
    "authors": {
        "Adam Kirk": "[email protected]"
    },
    "platforms": {
        "ios": "6.0",
        "osx": "10.8"
    },
    "source": {
        "git": "https://github.com/mysterioustrousers/MYSSharedSettings.git",
        "tag": "0.0.2"
    },
    "source_files": "MYSSharedSettings/*.{h,m}",
    "frameworks": "Foundation",
    "requires_arc": true,
    "dependencies": {
        "MYSRuntime": [
            "~> 0.0.2"
        ]
    }
}

Pin It on Pinterest

Share This