Giter Site home page Giter Site logo

propertymapper's Introduction

Hi there πŸ‘‹

I am Principal engineer and creator of apps and tools that are trusted by over 80,000 teamsβ€”including industry leaders Apple, Disney, and Airbnb.

I've just released a video course that you can join if you want to save lots of time creating apps for Apple platforms.

πŸš€ I'm available for consulting and speaking engagements. Feel free to reach out to me to discuss opportunities.

In the past, I led iOS development at The New York Times, worked on apps such as Headspace, The Browser Company, and created my own indie apps like Foldify.

Community Work

You can sponsor my work and get premium content on my blog.

My Expertise

I focus on creating maintainable architecture and improving developer experience and efficiency by:

  • πŸ€” Designing flexible architecture that is easy to maintain
  • βš™οΈ Creating automation for common code tasks and workflows
  • πŸ‘₯ Establishing best practices for architecture, testing, and workflows
  • πŸ“‹ As a consultant, I usually:
    • πŸ€” Perform code reviews for entire projects and provide clients with practical recommendations to improve their team efficiency and satisfaction (through better development experience and automation)
    • πŸ‘₯ Help establish best practices and provide architecture recommendations
    • πŸ› οΈ Design and implement flexible and pragmatic solutions for hard problems
  • πŸ§™ And much more...

Talking with Me

  • 🐦 My Twitter: @merowing_
  • πŸ’¬ Pronouns: He/Him

You can learn more about me and my past experience on my blog.

propertymapper's People

Contributors

adelinofaria avatar andrewsardone avatar cdzombak avatar cfdrake avatar chocochipset avatar eddpt avatar idcuesta avatar ilyannn avatar joostvanderborg avatar kevinvitale avatar krzysztofzablocki avatar krzyzanowskim avatar lino-silva avatar michaelarmstrong avatar miiha avatar octover avatar rdgborges avatar rodrigoaguilar avatar shaps-test avatar twealm 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

propertymapper's Issues

CocoaPods integration

CocoaPods support would be great.
I would create a podspec but a tag will be needed.
Have you thought about it?

Thanks a lot for this

Asserts when receiving an NSArray instead of an NSDictionary

Hi, I just updated to 2.5 and I'm really excited with the new features :)

Before the update I was using a modified version in which I surrounded some methods with a try/catch to avoid crashes in the testers devices because of the API changing constantly. Now I was thinking of use the new version to accomplish the same purpose, but I encountered a problem with an assertion.

JSON I expect:

{
    ...
    thing:Β 
        {
            a1 : "hello",
            ...
        },
    ...
}

Mapping:

    [KZPropertyMapper mapValuesFrom:properties 
                          toInstance:self
                       usingMapping:@{
                                  @"a1" : KZProperty(attribute1),
                                  }
     ];

JSON I'm reciving:

{
    ...
    thing:Β [],
    ...
}

This Asserts on line 252: AssertTrueOrReturn([key isKindOfClass:NSNumber.class]); inside the enumeration block.

The problem is natural. I'm giving an array to the mapper when it expects a dictionary. The crash is absolutely normal but with the new feature I was hoping that this won't happen anymore.
If this is the desired behaviour there is no problem ;)

KZCall on different object?

Let's say I have an User object, and an user belongs to a group.

@interface User : NSObject
@property (strong, nonatomic) NSString *firstName;
@property (strong, nonatomic) NSString *lastName;
@property (strong, nonatomic) Group *group;
@end

@interface Group : NSObject
@property (strong, nonatomic) NSString *name;
@end

Now, what I'd like to be able to do is something like this:

@implementation User

- (instancetype)initWithDict:(NSDictionary *)dict {
    self = [super init];

    KZPropertyMapper mapValuesFrom:dict toInstance:self usingMapping:@{
        @"name": KZProperty(firstName),
        @"lastname": KZProperty(lastName),
        @"group": KZCall(Group, groupWithDict:, group),
    }];

    return self;
}

@end

So, call [Group groupWithDict:dict] and save that result to self.group. However, I now constantly have to create an intermediary helper method on the object I'm parsing, so the user object now gets something like this:

- (id)groupWithDict:(NSDictionary *)dict {
    return [Group groupWithDict:dict];
}

After writing a bunch of classes like this, it gets really tedious to duplicate these methods like this. Is there any solution? It looked like KZCallT would be handy, but the property then needs to be on the target object instead of self.

Crash when mapping null object to a primitive

This test doesn't pass when trying to map a null object to, for example, an int:

        it(@"should handle NULL value for primitive value", ^{
          sourceDictionary = @{@"testValue" : [NSNull null]};
          mapping = @{@"testValue" : @"intNumber" };
          [[theBlock(^{
            testResult = [KZPropertyMapper mapValuesFrom:sourceDictionary toInstance:testObject usingMapping:mapping];
           }) shouldNot] raise];
           [[theValue(testResult) should] beTrue];
        });

Does it make any sense to fix this or it's just a bad approach and should use the library in other way?

Support for Swift

To whom it may concern,

This is a great library. However, when I tried to use it in Swift code, the Macro did not work well.

Is there any plan to roll out support for Swift?

Regards

Support for compound property?

I was wondering, how would I support compound property, for example, if the values of latitude and longitude are in the root dictionary and I want them to create a CLLocation instance. I couldn't thought of an elegant way to do it though except falling back to hand crafting loading.

Also, I was wondering if there's support for explicitly ignoring fields.

KVO notification

Hi,
I think you should move [instance willChangeValueForKey:mapping] & [instance didChangeValueForKey:mapping] into CoreData case.
Because KVC will automatic post change notification and it will trigger this twice.
Or do you have any other reason for this?

ISO 8601 date format

Just wanted to let you know that ISO 8601 is a rather complicated format and it's not easy to catch all of its possibilities with NSDateFormatter: for example, both 2015-07-01 and 2015-07-01T00:00:00 are allowed, but aren't parsed by current implementation.

It was very easy to combine iso-8601-date-formatter with KZPropertyMapper, but perhaps it should be used by default.

Crash when creating the date formatter

I've seen some crashes coming into a production app through Crashlytics at this line:
df = [[NSDateFormatter alloc] init];

I believe they happen because if multiple threads race during the creation of the date formatter, the if clause may not be enough to make sure everything is set up for all the remaining accesses, only a dispatch_once_t is.

This can lead to an incomplete set up for the date formatter.

PR will follow.

Support for NSEntityDescription instance

Hi,

Would be great if mapper could map values on NSEntityDescription instance. It's kind of exceptional, but looks it can be done with NSEntityDescription.properties

NSURL Issue

Expecting an NSURL and receiving __NSCFString

Logging ignored values and CocoaPods

This is more of a question and observation than an issue.

Currently ignored values are logged by default – users must #define KZPropertyMapperLogIgnoredValues 0 in order to stop the default logging. This is probably the right behavior, but it's awkward to actually define the preprocessor variable when using CocoaPods.

When declaring pod dependencies, it's not possible to #define variables. A user needs to add the #define within Pods/Pods-KZPropertyMapper-prefix.pch, but many people ignore the Pods/ directory so this setup would not persist across installs.

Given this, do you think a debug class method on KZPropertyMapper might be in order, say, +[KZPropertyMapper logIgnoredValues:], or is the preprocessor route good enough and CocoaPods users should commit their Pods/ directory?

Crashing with NSManagedObject

On line 168 in KZPropertyMapper.m objc_msgSend(instance, NSSelectorFromString(@"setPrimitiveValue:forKey:"), value, mapping);, when it tries to call setValue:withMapping:onInstance: it crashes with an EXC_BAD_ACCESS.

In my testing, this is occurring on an iPhone 5s, but not on a 4s or 5. My suspicion is that this is an issue with the new 64-bit architecture. I'm using MOGenerator to generate the models, but nothing special besides that.

Assertion failure - which property?

Hi, this is more of a question.

From the call stack below, how can I figure out which property causes the problem? Usually it happens when the API returns something I did not account for, but I never know where to start.

Thanks!

Cheers
Simon

2013-11-10 05:00:18.005 Passions[17581:70b] **\* Assertion failure in +[KZPropertyMapper validateMapping:withValuesArray:], /Users/simon/Documents/code/ObjC/iOS/Passions/Pods/KZPropertyMapper/KZPropertyMapper/KZPropertyMapper.m:192 2013-11-10 05:00:18.008 Passions[17581:70b] **\* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid condition not satisfying: [key isKindOfClass:NSNumber.class]' **\* First throw call stack: ( 0 CoreFoundation 0x01d5f5e4 **exceptionPreprocess + 180 1 libobjc.A.dylib 0x01ae28b6 objc_exception_throw + 44 2 CoreFoundation 0x01d5f448 +[NSException raise:format:arguments:] + 136 3 Foundation 0x00657fee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116 4 Passions 0x0005290b __52+[KZPropertyMapper validateMapping:withValuesArray:]_block_invoke + 363 5 CoreFoundation 0x01de840c __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke + 76 6 CoreFoundation 0x01de832e -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] + 238 7 CoreFoundation 0x01d4d525 -[NSDictionary enumerateKeysAndObjectsUsingBlock:] + 53 8 Passions 0x000526dc +[KZPropertyMapper validateMapping:withValuesArray:] + 284 9 Passions 0x00052556 +[KZPropertyMapper validateMapping:withValues:] + 854 10 Passions 0x000530d6 __57+[KZPropertyMapper validateMapping:withValuesDictionary:]_block_invoke + 342 11 CoreFoundation 0x01de840c __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke + 76 12 CoreFoundation 0x01de832e -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] + 238 13 CoreFoundation 0x01d4d525 -[NSDictionary enumerateKeysAndObjectsUsingBlock:] + 53 14 Passions 0x00052ec6 +[KZPropertyMapper validateMapping:withValuesDictionary:] + 278 15 Passions 0x00052519 +[KZPropertyMapper validateMapping:withValues:] + 793 16 Passions 0x0004f6a6 +[KZPropertyMapper mapValuesFrom:toInstance:usingMapping:errors:] + 182 17 Passions 0x0004f588 +[KZPropertyMapper mapValuesFrom:toInstance:usingMapping:] + 184 18 Passions 0x00055860 -[LFMAlbumInfo initWithJson:] + 2608 19 Passions 0x0005ea32 __57-[LastFmFetchr getInfoForAlbum:byArtist:mbid:completion:]_block_invoke_2 + 146 20 Passions 0x0005f97a -[LastFmFetchr handleRequestSuccess:task:methodParamValue:jsonContentKey:success:failure:] + 1066 21 Passions 0x0005e91b __57-[LastFmFetchr getInfoForAlbum:byArtist:mbid:completion:]_block_invoke + 363 22 Passions 0x000176f7 __55-[AFHTTPSessionManager GET:parameters:success:failure:]_block_invoke + 231 23 Passions 0x0003a3d5 __72-[AFURLSessionManagerTaskDelegate URLSession:task:didCompleteWithError:]_block_invoke_2 + 213 24 libdispatch.dylib 0x0295d7f8 _dispatch_call_block_and_release + 15 25 libdispatch.dylib 0x029724b0 _dispatch_client_callout + 14 26 libdispatch.dylib 0x0296075e _dispatch_main_queue_callback_4CF + 340 27 CoreFoundation 0x01dc4a5e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE** + 14 28 CoreFoundation 0x01d056bb __CFRunLoopRun + 1963 29 CoreFoundation 0x01d04ac3 CFRunLoopRunSpecific + 467 30 CoreFoundation 0x01d048db CFRunLoopRunInMode + 123 31 GraphicsServices 0x02f629e2 GSEventRunModal + 192 32 GraphicsServices 0x02f62809 GSEventRun + 104 33 UIKit 0x00c75d3b UIApplicationMain + 1225 34 Passions 0x000025ed main + 141 35 libdyld.dylib 0x02c0470d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

Relationship mapping

To whom it may concern

I have been using a couple of data mapping libraries and this one seems to be very light weight and easy to use. However one of the thing I would love to have is relationship mapping. Like one-one, one-many relationship

I.e:
With this dictionary
@{
@"videoURL" : @"http://test.com/video.mp4",
@"name" : @"Some Cool Video",
@"videoType" : [NSNull null],
@"sub_object" : @{
@"title" : @616,
@"arbitraryData" : @"data"
}
}

Can I map the sub_object to a class that I already have

@interface MyClass: NSObject

@Property NSString title;
@Property NSString arbitraryData

@EnD

Kind regards
Leon

Suppressing error messages

Is it possible, to somehow disable warnings like:

KZPropertyMapper: Ignoring mapping from matchTime to matchTime because type (null) does NOT match NSString

I'm avare that this might be null, NSString out of null is empty. I'm ready for that, but it just overflows my log and would not like to see it.

Better warning message for missing Box custom methods

We could modify the Assertion code to handle better cases where the developer forgot to write the code to handle the custom Box.

    SEL mappingSelector = NSSelectorFromString([NSString stringWithFormat:@"boxValueAs%@:", mappingType]);
    AssertTrueOrReturnNoBlock([self respondsToSelector:mappingSelector], ^(NSError *error) {
    });

In the AssertTrueOrReturnNoBlock we could print the expected selector.

validationErrors array is always null

I'm using:

 NSArray *validationErrors;
   BOOL isItemValid = [KZPropertyMapper mapValuesFrom:dic toInstance:self
                                          usingMapping:@{@"id" : KZProperty(Id),
                                                         @"name" : KZProperty(name),
                                                         @"has_sentiment" : KZProperty(tonality)
                                                         }
                                                errors:&validationErrors];

NSLog(@"validationErrors: %@", validationErrors);

And this I see in logs:

KZPropertyMapper: Ignoring mapping from name to name because type __NSSingleEntryDictionaryI does NOT match NSString
 KZPropertyMapper Error: Invalid condition not satisfying: isSameTypeObject
 arrErrors: (null)

What I'm doing wrong?

CocoaPods and 2.5.1?

Hi, it seems to be that 2.5.1 is not on CocoaPods? I'm getting this error. 2.5.0 is working!

[!] Unable to satisfy the following requirements:

- `KZPropertyMapper (~> 2.5.1)` required by `Podfile`

Prime Business Spaces: Elan The Mark, Gurgaon

Discover the ultimate business destination at Elan The Mark in Gurgaon. Renowned as the best Elan commercial project, it offers top-notch amenities and strategic location for success. Elevate your business in a dynamic environment designed for growth and prosperity. With prime spaces tailored to meet your needs, unlock the potential for unparalleled success at Elan The Mark in Gurgaon.

Ability to Propagate Errors when using Custom Boxing / Call

Lets say I have a JSON object like this:

  { 
       success: false,
       error: {code: 1, message: "Something was wrong!"},
       data: nil
  }

And I wan't to map object like this:

@interface Response : NSObject
@property (assign, nonatomic) BOOL    isSuccess;
@property (strong, nonatomic) id      data;
@property (strong, nonatomic) NSError *error;
@end

I can map error with KZCall or by custom boxing. But this methods unable to specify any errors during certain class instantiation or mapping. Is there any way to fix it with current library implementation?

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.