GithubHelp home page GithubHelp logo

dhennessy / papreferences Goto Github PK

View Code? Open in Web Editor NEW
319.0 319.0 32.0 80 KB

Using @dynamic to access NSUserDefaults.

Home Page: http://www.peerassembly.com/blog/using-dynamic-properties-to-access-nsuserdefaults.html

License: Other

Ruby 2.44% Objective-C 97.56%

papreferences's People

Contributors

alkozin avatar dhennessy avatar egeakpinar avatar evgeniyd avatar migrs avatar zyuanming avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

papreferences's Issues

Creating a BasePreferences class for different targets to subclass

I love this class, and have been using it to drive preferences for many different targets in my project.

Today I decided to try to reduce the amount of code that was getting duplicated each time I created a new target. Instead of using a direct subclass of PAPreferences directly:

  • PAPreferences
    • MyPreferences // where all my @properties are defined

I wanted to create a base class, and then each target would simply implement a subclass of that:

  • PAPreferences
    • MyPreferencesBase // where all my @properties are defined
      • MyPreferences // now I just have to tweak each @Property in the init

Unfortunately this isn't proving successful. I'm getting "unrecognized selector sent to instance" when trying to access a @Property in MyPreferences that has been defined in MyPreferencesBase.

Am I doing something wrong or is this type of setup unsupported?

Thanks again for the wonderful class.

Log Message

Some times, when I tried to set a property... the library return me the next msg:

"Type of activityLevel is not supported by PAPreferences."

How can I solve this?

Regards

Saving array of NSCoding compliant classes

First things first - love your library.

I tried saving an array of NSCoding compliant class but it's throwing 'not plist compatible' exception. When I try saving it as a single object (not an array), it works.

We'd like to keep using PAPreferences in our project, how tricky would it be to add support for array of custom classes?

Thanks,
Ege

How to make PAPreferences support Swift?

I want inherit one swift class from PAPreferences, but don't know how to deal with @dymamic

class MUSPreferences : PAPreferences
{
    @dynamic var firstVersionInstalled:String

    @dynamic var latestVersionInstalled:String
    ...
}

cause the init method in PAPreferences. will dynamic assign all value from NSUserDefault to the property, so I don't need to set them in the MUSPreferences's init(), but if I don't set them, xcode will report error "Property xxx not intiialized at super.init call", Do you have some solution to deal with this problem?

Not support ENUM?

typedef NS_ENUM(NSUInteger, RJCountryEnum) {
RJCountryEnum_China,
RJCountryEnum_Usa,
};

then I call:
kUserManager.country = RJCountryEnum_Usa;

error:
[RJPreferences setCountry:]: unrecognized selector sent to instance 0x1c0224e20

Receiving logging warning message for supported types

I have a BOOL named hasSeenIntro defined as a preference value.

When running my app I get: "Type of hasSeenIntro is not supported by PAPreferences"

Looking in the code, it looks that the warning is in the wrong location

if ([self isValidType:type]) {
  NSLog(@"Type of %@ is not supported by PAPreferences", name);
  _dynamicProperties[getterName] = [[PAPropertyDescriptor alloc] initWithName:name type:type isSetter:NO];
  _dynamicProperties[setterName] = [[PAPropertyDescriptor alloc] initWithName:name type:type isSetter:YES];
}

Tag in Podspec should be updated for latest commits

Current .podspec points to tag 0.4, which itself targeted to a commit made at Nov 19

s.version      = "0.4"

# other things...

s.source       = { :git => 'https://github.com/dhennessy/PAPreferences.git', :tag => s.version.to_s } 

I can submit a pull request with these changes.

Add a way to make all or some data encrypted

It's usually a good thing to have some properties encrypted when your app is dealing with InApp Purchases or any sensitive data you don't want to be accessed via jailbreaking.

A simple way would be to make this work by convention, for instance requiring a property to be prefixed by _secret_ in order to keep it stored encrypted.

The developer would also need to register a secret key in order to get the encryption to work.

You can look at SecureNSUserDefaults which is a great addition to NSUserDefaults for handling this kind of needs.

Inherited twice will error

I create class RJPreferences : PAPreferences and class TestPreferences: RJPreferences,.
Error:-[TestPreferences setIpAddress:]: unrecognized selector sent to instance 0x1c42230c0

Support custom NSUserDefaults instances

NSUserDefaults has an initialiser -initWithSuiteName: that can be used to create an instance to preferences of another application, as well as methods to add/remove suites to a specific user default instance. I think PAPreferences can support this (and more) by exposing an additional initialiser -initWithUserDefaults: that initialises an instance backed by a particular user default instance, instead of always using [NSUserDefaults standardUserDefaults]. The current behaviour can be maintained by falling back to the standard user defaults if the initialiser is called with nil.

What do you think about this feature? I can produce a pull request on this if the above is reasonable.

Great but..

It's great, really straightforward. However, I kept running into a race condition due to [synchronize] not being called quick enough. Hence it wouldn't persist the saved data.

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.