dhennessy / papreferences Goto Github PK
View Code? Open in Web Editor NEWUsing @dynamic to access NSUserDefaults.
Home Page: http://www.peerassembly.com/blog/using-dynamic-properties-to-access-nsuserdefaults.html
License: Other
Using @dynamic to access NSUserDefaults.
Home Page: http://www.peerassembly.com/blog/using-dynamic-properties-to-access-nsuserdefaults.html
License: Other
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:
I wanted to create a base class, and then each target would simply implement a subclass of that:
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.
This is a great framework! I'm surprised this repo doesn't get more stars! Thanks again!
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
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
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?
When receiving NSNotification
from PAPreferences
instance, it does not have info about what exactly the property name that is changed.
It would be useful to have such an info, so the callback can easily update other data/UI upon the change.
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
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];
}
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.
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.
I create class RJPreferences : PAPreferences and class TestPreferences: RJPreferences,.
Error:-[TestPreferences setIpAddress:]: unrecognized selector sent to instance 0x1c42230c0
it'd be nice to get a quick and dirty example of the functionality of the project
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.
I would like to change PAPropertyDescriptor’s name
property to something more semantically accurate like key
, defaultsKey
or userDefaultsKey
. Discuss. ;)
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.