Skip to content

Commit

Permalink
Replace deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyKuryanov committed Jul 10, 2018
1 parent c2e8e4f commit 2783d26
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions librato-iOS/Metrics/LibratoMetric.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,41 +69,41 @@ + (NSDictionary *)JSONKeyPathsByPropertyKey

+ (NSValueTransformer *)measureTimeJSONTransformer
{
return [MTLValueTransformer reversibleTransformerWithForwardBlock:^id(NSNumber *epoch) {
return [MTLValueTransformer transformerUsingForwardBlock:^id(NSNumber *epoch, BOOL *success, NSError **error) {
return [NSDate dateWithTimeIntervalSince1970:epoch.integerValue];
} reverseBlock:^id(NSDate *date) {
} reverseBlock:^id(NSDate *date, BOOL *success, NSError **error) {
return @(floor(date.timeIntervalSince1970));
}];
}


+ (NSValueTransformer *)nameJSONTransformer
{
return [MTLValueTransformer reversibleTransformerWithForwardBlock:^id(NSString *name) {
return [MTLValueTransformer transformerUsingForwardBlock:^id(NSString *name, BOOL *success, NSError **error) {
NSAssert(name.length > 0, @"Measurements must be named");
return name.alm_sanitizedForMetric;
} reverseBlock:^id(NSString *name) {
} reverseBlock:^id(NSString *name, BOOL *success, NSError **error) {
return name.alm_sanitizedForMetric;
}];
}


+ (NSValueTransformer *)sourceJSONTransformer
{
return [MTLValueTransformer reversibleTransformerWithForwardBlock:^id(NSString *source) {
return [MTLValueTransformer transformerUsingForwardBlock:^id(NSString *source, BOOL *success, NSError **error) {
return source.alm_sanitizedForMetric;
} reverseBlock:^id(NSString *source) {
} reverseBlock:^id(NSString *source, BOOL *success, NSError **error) {
return (source.length ? source.alm_sanitizedForMetric : nil);
}];
}


+ (NSValueTransformer *)valueJSONTransformer
{
return [MTLValueTransformer reversibleTransformerWithForwardBlock:^id(NSNumber *value) {
return [MTLValueTransformer transformerUsingForwardBlock:^id(NSNumber *value, BOOL *success, NSError **error) {
NSAssert([self.class isValidValue:value], @"Boolean is not a valid metric value");
return value;
} reverseBlock:^id(NSNumber *value) {
} reverseBlock:^id(NSNumber *value, BOOL *success, NSError **error) {
return value;
}];
}
Expand All @@ -113,7 +113,7 @@ + (NSValueTransformer *)valueJSONTransformer
- (NSDictionary *)JSONDictionary
{
NSArray *nonNullableKeys = @[@"source"];
__block NSMutableDictionary *jsonDict = [MTLJSONAdapter JSONDictionaryFromModel:self].mutableCopy;
__block NSMutableDictionary *jsonDict = [MTLJSONAdapter JSONDictionaryFromModel:self error:nil].mutableCopy;
[nonNullableKeys enumerateObjectsUsingBlock:^(NSString *key, NSUInteger idx, BOOL *stop) {
if ([jsonDict.allKeys containsObject:key] && (jsonDict[key] == NSNull.null || jsonDict[key] == nil))
{
Expand Down

0 comments on commit 2783d26

Please sign in to comment.