Comments (4)
- Boxing or KZCall -> https://github.com/krzysztofzablocki/KZPropertyMapper#advanced-usage
- Ignoring is automatic if you don't specify mapping, not sure what else you'd like to do here?
from propertymapper.
Thanks for the response man! :D Though I still have some enquiries, sorry!
- I think boxing/call only for 1 key to 1 property mapping though. I see that KZList allows 1 key to many properties mapping. I couldn't really figure out how to do boxing/call for many keys to 1 property mapping though.
e.g. for the following JSON
{
"id" : "12345",
"name" : "Singapore",
"latitude" : 1.35,
"longitude" : 103.81
}
NSDictionary *mapping = @{
@"id" : KZProperty(identifier),
@"name" : KZProperty(name),
@"latitude" : KZCall(latLngToCLLocation:forKey:, location),
@"longitude" : KZCall(latLngToCLLocation:forKey:, location),
};
Since the order of execution of the property mapper is undefined, the only solution I could think of is to implement something similar to the following latLngToCLLocation:forKey:
method:
- (CLLocation *)latLngToCLLocation:(NSNumber *)latOrLng forKey:(NSString *)key {
static NSString *prevKey = nil;
static NSNumber *prevLatOrLng = nil;
if (prevKey && prevLatOrLng) {
CLLocation *location = nil;
// TODO: ([email protected]) Create location from lat & lng.
prevKey = nil;
prevLatOrLng = nil;
return location;
} else {
prevKey = key;
prevLatOrLng = latOrLng;
return nil;
}
}
The solution I current have as you can see is pretty error prone and have multiple area of failure which would have to be guarded against. I'm just wondering if there's better solution for many keys to 1 property mapping. :) It not a showstopper cause I can always revert to manual mapping.
- I love that it reports unmapped key, I can see myself skipping KZPropertyMapper for some more complex scenario like the above.
Thanks for this great gem, I really like it.
from propertymapper.
Ah, so boxing and KZCall are meant to be used for sub-objects, if you had those properties inside a root then you'd just use that root as the key e. g. something like this
{
"id" : "12345",
"name" : "Singapore",
"location" : {
"latitude" : 1.35,
"longitude" : 103.81
}
}
@"location" : KZCall(CLLocationFromLocation:, location)
In your case, I'd just do a dynamic / lazy configured public property, then you can keep normal mapping for lat/lon inside your class, but public interface would use CLLocation ?
from propertymapper.
Ah thanks! I didn't thought of that! Haha! I'm over thinking it!
from propertymapper.
Related Issues (20)
- Assertion failure - which property? HOT 5
- Update CocoaPods with the latest commit HOT 2
- Asserts when receiving an NSArray instead of an NSDictionary HOT 3
- No testing of validation errors in KZPropertyMapperValidatorTests.m HOT 5
- Crash when creating the date formatter
- Support for Swift HOT 1
- CocoaPods and 2.5.1? HOT 1
- KZCall on different object? HOT 4
- Doesn't work when there's a getter method defined HOT 2
- Support for NSEntityDescription instance HOT 2
- Nullify value for missing key/default value HOT 1
- ISO 8601 date format HOT 1
- Ability to Propagate Errors when using Custom Boxing / Call HOT 3
- No mapping if value from custom boxing is nil HOT 7
- Suppressing error messages HOT 4
- Crash when converting from number to NSDate HOT 2
- Crash when mapping null object to a primitive HOT 1
- validationErrors array is always null HOT 2
- Better warning message for missing Box custom methods HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from propertymapper.