This repository has been archived.
If you want to be a maintainer, please contact me an email.
MantleArrayExtension support mutual conversion between Model object and character-delimited String with Mantle.
Mantle only support Json and Dictionary.
This library is an extension that convert between array and model with Mantle.
- Support these
- Split a string with the specified character and convert it to model
- Convert between array and model
- Customizable transformer
Model framework for Cocoa and Cocoa Touch
MantleArrayExtension is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'MantleArrayExtension'
// String to Model
id<MAESerializing> model = [MAEArrayAdapter modelOfClass:model.class
fromString:@"2017-01-29, 'Alice Brown', 1, 2, 3"
error:&error];
// Model to String
NSString* string = [MAEArrayAdapter stringFromModel:model
error:&error];
Model MUST inherit MTLModel and conforms MAEArraySerializing.
#pragma mark - MAEArraySerializing
+ (NSArray* _Nonnull)formatByPropertyKey
{
return @[ @"date", MAESingleQuoted(@"name"), MAEVariadic(@"scores") ];
}
+ (unichar)separator
{
return ',';
}
+ (BOOL)ignoreEdgeBlank
{
return YES;
}
@"propetyName"
- Double quoted-string, single quoted-string or enumerate-string
MAEQuoted(@"propertyName")
- Double quoted-string
MAESingleQuoted(@"propertyName")
- Single quoted-string
MAEOptional(@"propertyName")
- Optional
MAEVariadic(@"propertyName")
- Group from this position as one array.
MAERaw(@"rawString")
,MAERawEither(@[@"value1", @"value2"])
- The string expect one of specified strings
MAERawEither(@[@"value1", @"value2"]).withProperty(@"propertyName")
MAERaw
orMAERawEither
associate with property.
You can use serializer for MAEArraySerializing object.
MAEArrayAdapter # stringTransformerWithArrayModelClass:
MAEArrayAdapter # variadicTransformerWithArrayModelClass:
For MAEArraySerializing property, it is used by default, so you do not need to specify it.
Please refer to documentation, unit tests and Mantle.
Pull request is welcome =D