https://github.com/kelp404/valueinjector
Cocoa ValueInjector provides converting weak typing to strong typing. Injecting value from NSDictionary to custom class and initialization NSDictionary with custom class.
https://github.com/kelp404/valueinjector
Last synced: 2 months ago
JSON representation
Cocoa ValueInjector provides converting weak typing to strong typing. Injecting value from NSDictionary to custom class and initialization NSDictionary with custom class.
- Host: GitHub
- URL: https://github.com/kelp404/valueinjector
- Owner: kelp404
- Created: 2012-05-08T13:46:54.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2013-01-29T12:14:24.000Z (over 12 years ago)
- Last Synced: 2025-04-02T20:57:00.189Z (2 months ago)
- Language: Objective-C
- Homepage: http://kelp.phate.org/2012/05/inject-value-from-nsdictionary-to.html
- Size: 483 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#ValueInjector
http://kelp.phate.org/2012/05/inject-value-from-nsdictionary-to.htmlKelp http://kelp.phate.org/
MIT LicenseCocoa ValueInjector provides converting weak typing to strong typing.
It includes two function injecting value from NSDictionary to custom class and initialization NSDictionary with custom class.
After import ValueInjector.h, NSObject will be add a new message "injectFromObject", and NSDictionary will be add a new message "initWithObject".
**injectFromObject** converts weak typing to strong typing. When you use JSONKit parsing json then get a NSDictionary object, you can use injectFromObject to convert NSDictionary to custom class.
**initWithObject** converts custom class to NSDictionary. When you want to serialize custom class(strong typing), you can use initWithObject to initialize NSDictionary with custom class.
##Inject value from NSDictionary to custom class
```objective-c
NSObject (ValueInjector)
- (id)injectFromObject:(NSObject *)object;
```
```objective-c
NSDictionary *dictionary = [[[NSDictionary alloc] init] ...];
YourClass *model = [[YourClass alloc] init];
[model inijectFromObject:dictionary];
```##Initialize NSDictionary with custom class
```objective-c
NSDictionary (ValueInjector)
- (id)initWithObject:(NSObject *)object;
```
```objective-c
YourClass *model = [[YourClass alloc] init];
// set value of model ...
NSDictionary *dictionary = [[NSDictionary alloc] initWithObject:model];
```Cocoa Reflection Refer: https://developer.apple.com/library/mac/#documentation/cocoa/Reference/ObjCRuntimeRef/Reference/reference.html