Skip to content

Commit 9e72d11

Browse files
author
Shan Ul Haq
committed
added new methods to take custom NSDateFormatter object
1 parent 6613011 commit 9e72d11

File tree

4 files changed

+102
-8
lines changed

4 files changed

+102
-8
lines changed

Podfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
PODS:
2-
- Realm (0.91.1):
3-
- Realm/Headers (= 0.91.1)
4-
- Realm/Headers (0.91.1)
2+
- Realm (0.92.3):
3+
- Realm/Headers (= 0.92.3)
4+
- Realm/Headers (0.92.3)
55

66
DEPENDENCIES:
77
- Realm
88

99
SPEC CHECKSUMS:
10-
Realm: b9c1fd9defa26aa7276ce938a8df52ec81f24528
10+
Realm: bf604805d5e897850da488260f93889f510924b3
1111

12-
COCOAPODS: 0.36.3
12+
COCOAPODS: 0.37.1

SHModelObject/SHModelObject/SHModelObject.h

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
* @param dictionary dictionary containing key/value pairs for the object
6262
* @param option `kDateConverstionOption` to determine what to do when the value from dictionary is a DOT.NET Date
6363
*type.
64-
* @param inputDateFormat NSDateFormatter format specifier which will be used to format the input date.
64+
* @param inputDateFormat NSDateFormatter format specifier which will be used to format the input date. this will use
65+
*the systemTimeZone to create the formatter
6566
* @param mapping dictionary to define the mappings for date conversion and array <-> object.
6667
*
6768
* @return object of type instancetype populated with the values from `dictionary`
@@ -71,6 +72,23 @@
7172
inputDateFormat:(NSString *)inputDateFormat
7273
mappings:(NSDictionary *)mapping;
7374

75+
/**
76+
* class initializer
77+
*
78+
* @param dictionary dictionary containing key/value pairs for the object
79+
* @param option `kDateConverstionOption` to determine what to do when the value from dictionary is a DOT.NET Date
80+
*type.
81+
* @param inputDateFormatter NSDateFormatter object which will be used to format the input date.
82+
* @param mapping dictionary to define the mappings for date conversion and array <-> object.
83+
*
84+
* @return object of type instancetype populated with the values from `dictionary`
85+
*/
86+
87+
- (instancetype)initWithDictionary:(NSDictionary *)dictionary
88+
dateConversionOption:(kDateConversionOption)option
89+
inputDateFormatter:(NSDateFormatter *)inputDateFormatter
90+
mappings:(NSDictionary *)mapping;
91+
7492
/**
7593
* static variant of class initializer with nil check for the dictionary passed
7694
*
@@ -114,7 +132,8 @@
114132
* @param dictionary dictionary containing key/value pairs for the object
115133
* @param option `kDateConverstionOption` to determine what to do when the value from dictionary is a DOT.NET Date
116134
*type.
117-
* @param inputDateFormat NSDateFormatter format specifier which will be used to format the input date.
135+
* @param inputDateFormat NSDateFormatter format specifier which will be used to format the input date. this will use
136+
*the systemTimeZone to create the formatter
118137
* @param mapping dictionary to define the mappings for date conversion and array <-> object.
119138
*
120139
* @return object of type instancetype populated with the values from `dictionary`
@@ -124,6 +143,22 @@
124143
inputDateFormat:(NSString *)inputDateFormat
125144
mappings:(NSDictionary *)mapping;
126145

146+
/**
147+
* static variant of class initializer with nil check for the dictionary passed
148+
*
149+
* @param dictionary dictionary containing key/value pairs for the object
150+
* @param option `kDateConverstionOption` to determine what to do when the value from dictionary is a DOT.NET Date
151+
*type.
152+
* @param inputDateFormatter NSDateFormatter object which will be used to format the input date.
153+
* @param mapping dictionary to define the mappings for date conversion and array <-> object.
154+
*
155+
* @return object of type instancetype populated with the values from `dictionary`
156+
*/
157+
+ (instancetype)objectWithDictionary:(NSDictionary *)dictionary
158+
dateConversionOption:(kDateConversionOption)option
159+
inputDateFormatter:(NSDateFormatter *)inputDateFormatter
160+
mappings:(NSDictionary *)mapping;
161+
127162
/**
128163
* update the instance with new dictionary values
129164
*
@@ -155,7 +190,8 @@
155190
* @param dictionary dictionary containing key/value pairs for the object
156191
* @param option `kDateConverstionOption` to determine what to do when the value from dictionary is a DOT.NET Date
157192
*type.
158-
* @param inputDateFormat NSDateFormatter format specifier which will be used to format the input date.
193+
* @param inputDateFormat NSDateFormatter format specifier which will be used to format the input date. this will use
194+
*the systemTimeZone to create the formatter
159195
* @param mapping dictionary to define the mappings for date conversion and array <-> object.
160196
*
161197
* @return object of type instancetype populated with the values from `dictionary`
@@ -165,6 +201,22 @@
165201
inputDateFormat:(NSString *)inputDateFormat
166202
mappings:(NSDictionary *)mapping;
167203

204+
/**
205+
* update the instance with new dictionary values
206+
*
207+
* @param dictionary dictionary containing key/value pairs for the object
208+
* @param option `kDateConverstionOption` to determine what to do when the value from dictionary is a DOT.NET Date
209+
*type.
210+
* @param inputDateFormatter NSDateFormatter object which will be used to format the input date.
211+
* @param mapping dictionary to define the mappings for date conversion and array <-> object.
212+
*
213+
* @return object of type instancetype populated with the values from `dictionary`
214+
*/
215+
- (instancetype)updateWithDictionary:(NSDictionary *)dictionary
216+
dateConversionOption:(kDateConversionOption)option
217+
inputDateFormatter:(NSDateFormatter *)inputDateFormatter
218+
mappings:(NSDictionary *)mapping;
219+
168220
@end
169221

170222
@interface NSString (Additions)

SHModelObject/SHModelObject/SHModelObject.m

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,23 @@ + (instancetype)objectWithDictionary:(NSDictionary *)dictionary
119119
mappings:mapping];
120120
}
121121

122+
+ (instancetype)objectWithDictionary:(NSDictionary *)dictionary
123+
dateConversionOption:(kDateConversionOption)option
124+
inputDateFormatter:(NSDateFormatter *)inputDateFormatter
125+
mappings:(NSDictionary *)mapping {
126+
if (nil == dictionary || ![dictionary isKindOfClass:[NSDictionary class]]) {
127+
return nil;
128+
}
129+
130+
if ([dictionary isKindOfClass:[NSNull class]]) {
131+
return nil;
132+
}
133+
return [[[self class] alloc] initWithDictionary:dictionary
134+
dateConversionOption:option
135+
inputDateFormatter:inputDateFormatter
136+
mappings:mapping];
137+
}
138+
122139
//
123140
- (instancetype)initWithDictionary:(NSDictionary *)dictionary;
124141
{
@@ -158,6 +175,19 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary
158175
return self;
159176
}
160177

178+
- (instancetype)initWithDictionary:(NSDictionary *)dictionary
179+
dateConversionOption:(kDateConversionOption)option
180+
inputDateFormatter:(NSDateFormatter *)inputDateFormatter
181+
mappings:(NSDictionary *)mapping {
182+
if ((self = [super init])) {
183+
return [self updateWithDictionary:dictionary
184+
dateConversionOption:option
185+
inputDateFormatter:inputDateFormatter
186+
mappings:mapping];
187+
}
188+
return self;
189+
}
190+
161191
// NSCoding
162192
- (NSArray *)propertyNames {
163193
NSMutableArray *array = [NSMutableArray array];
@@ -257,6 +287,18 @@ - (instancetype)updateWithDictionary:(NSDictionary *)dictionary
257287
return [self updateWithDictionary:dictionary];
258288
}
259289

290+
- (instancetype)updateWithDictionary:(NSDictionary *)dictionary
291+
dateConversionOption:(kDateConversionOption)option
292+
inputDateFormatter:(NSDateFormatter *)inputDateFormatter
293+
mappings:(NSDictionary *)mapping {
294+
_converstionOption = option;
295+
_inputDateFormat = kInputDateFormatCustom;
296+
_customFormatter = inputDateFormatter;
297+
_mappings = mapping;
298+
299+
return [self updateWithDictionary:dictionary];
300+
}
301+
260302
#pragma mark - SHModalSerialization protocol methods
261303

262304
- (void)serializeValue:(id)value withKey:(id)key {

0 commit comments

Comments
 (0)