GithubHelp home page GithubHelp logo

lzm470445107 / myssharedsettings Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mysterioustrousers/myssharedsettings

0.0 2.0 0.0 138 KB

Access local settings and settings shared via iCloud with properties.

License: MIT License

myssharedsettings's Introduction

MYSSharedSettings

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.

myssharedsettings's People

Contributors

atomkirk avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.