KiteJSONValidator icon indicating copy to clipboard operation
KiteJSONValidator copied to clipboard

Develop

Open nut-code-monkey opened this issue 9 years ago • 7 comments

Merge branch 'master' into develop

NSError as a result of validation/schema adding

nut-code-monkey avatar Mar 06 '15 00:03 nut-code-monkey

@samskiter this patch is going to break backward compatibility. For the existing library users it may be like #define true false .

Still, I agree that NSError should be returned by the affected method.

// AS IS
-(BOOL)validateJSONData:(NSData*)jsonData withSchemaData:(NSData*)schemaData;

// from the patch
-(NSError*)validateJSONData:(NSData*)jsonData withSchemaData:(NSData*)schemaData;


// My proposal
// follows Cocoa conventions
-(BOOL)validateJSONData:(NSData*)jsonData 
         withSchemaData:(NSData*)schemaData
                  error:(NSError**)outError;

dodikk avatar Mar 16 '15 13:03 dodikk

@dodikk that's a great catch! thank you. My head is in Java mode at the minute and I forgot about the auto cast. also, this is actually the way i prefer to return errors if any - more consistent with apple's APIs and other libraries

@nut-code-monkey sorry for another delay on this PR.

samskiter avatar Mar 16 '15 14:03 samskiter

@samskiter , I think, these days I'll finally get a chance (in terms of time) to add your validator to my project. Eventually, I'll adopt these changes and remaster the API in the Cocoa way so that you'll get a patch from me.

P.S. @samskiter , I guess, this one is no longer relevant and can be closed. https://github.com/samskiter/KiteJSONValidator/pull/9

dodikk avatar Mar 16 '15 16:03 dodikk

@samskiter spent some of my leisure time trying to make the API follow the cocoa style https://github.com/dodikk/KiteJSONValidator/commit/7db8daee50fc3488d80c1e157ebfe57c5a235cb1

I can't afford spending so much time copy-pasting the if (NULL != outError) thing and structuring "return" statements. So, I'm giving up for now. Sorry.

dodikk avatar Mar 22 '15 10:03 dodikk

It would be a lot easier if I could use NSAssert(NULL != outError) rather than if statements. It would makes the changes so much more simple.

Such policy makes sense since it will be a lot harder to ignore validation errors. @samskiter , what do you think?

dodikk avatar Mar 22 '15 10:03 dodikk

Hi @dodikk thanks very much for your efforts. this is on my TODO list to sort out properly. It does look a little smelly that we have to have a lot of checks agains NULL (this should probably be nil by the way). so I will have to take a closer look.

samskiter avatar Apr 01 '15 09:04 samskiter

It does look a little smelly that we have to have a lot of checks agains NULL (this should probably be nil by the way).

That's how out parameters are done in "plain old C". And yes, apple allows NULL errors in their own API.


this should probably be nil by the way

No, it should not. NSError* (one star) and NSError** (two stars) are two completely different types. http://nshipster.com/nil/

dodikk avatar Apr 01 '15 11:04 dodikk