Giter Site home page Giter Site logo

Comments (4)

krzysztofzablocki avatar krzysztofzablocki commented on May 25, 2024
  1. Boxing or KZCall -> https://github.com/krzysztofzablocki/KZPropertyMapper#advanced-usage
  2. Ignoring is automatic if you don't specify mapping, not sure what else you'd like to do here?

from propertymapper.

lxcid avatar lxcid commented on May 25, 2024

Thanks for the response man! :D Though I still have some enquiries, sorry!

  1. 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.

  1. 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.

krzysztofzablocki avatar krzysztofzablocki commented on May 25, 2024

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.

lxcid avatar lxcid commented on May 25, 2024

Ah thanks! I didn't thought of that! Haha! I'm over thinking it!

from propertymapper.

Related Issues (20)

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.