Latest 0.1.0
Homepage https://github.com/opedge/PropertySanitizer
License MIT
Platforms ios 7.0, requires ARC
Authors

Validates object property values for class and protocol conformity.

CI Status
Version
License
Platform

Description

PropertySanitizer was written to solve problem with Objective-C dynamic nature.
When you parse JSON from server API response and you are unsure about property types at runtime, you should check your model properties to make your app fail earlier than crash somewhere in UI layer.

For example:

@class Account : NSObject

@property (nonatomic, strong) NSNumber *balance;
...

@end

account.balance = [JSONDictionary valueForKey:@"user_balance"]; // May fail if "user_balance" is string

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

This library has one method for validation:

@interface NSObject (PRSSanitizer)

- (BOOL)prs_validatePropertiesValuesWithError:(NSError * __autoreleasing *)error;

@end

Example:

account.balance = [JSONDictionary valueForKey:@"user_balance"]; // May fail if "user_balance" is string
NSError *validationError;
BOOL valid = [account prs_validatePropertiesValuesWithError:&validationError];
if (valid) {
    // Everythind is ok
} else {
    // You can check for actual error code
    if ([checkError.domain isEqualToString:PRSSanitizerErrorDomain] && 
         checkError.copy == PRSSanitizerErrorValueInvalidClass) {
        // Invalid class error
    }
}

For error codes look at NSObject+PRSSanitizer.h file.

Requirements

- Supported build target - iOS 8.3
- Earliest supported deployment target - iOS 7.0

Installation

PropertySanitizer is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "PropertySanitizer"

Author

Oleg Poyaganov, [email protected]

License

PropertySanitizer is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "PropertySanitizer",
    "version": "0.1.0",
    "summary": "Validate object property values for class and protocol conformity.",
    "description": "PropertySanitizer was written to solve problem with Objective-C dynamic nature. When you parse JSON from server API response and you are unsure about property types at runtime, you should check your model properties to make your app fail earlier than crash somewhere in UI layer.",
    "homepage": "https://github.com/opedge/PropertySanitizer",
    "license": "MIT",
    "authors": {
        "Oleg Poyaganov": "[email protected]"
    },
    "source": {
        "git": "https://github.com/opedge/PropertySanitizer.git",
        "tag": "0.1.0"
    },
    "social_media_url": "https://twitter.com/opedge",
    "platforms": {
        "ios": "7.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "public_header_files": "Pod/Classes/**/*.h"
}

Pin It on Pinterest

Share This