-
Notifications
You must be signed in to change notification settings - Fork 0
/
DCWind.m
66 lines (54 loc) · 1.85 KB
/
DCWind.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// DCWind.m
#import "DCWind.h"
#import <objc/runtime.h>
#import <Weather/WeatherWindSpeedFormatter.h>
@implementation DCWindSpeed
- (instancetype)init:(CGFloat)windSpeed {
self = [super init];
if (self) {
self.windSpeed = windSpeed;
}
return self;
}
- (BOOL)usesMetricSystem {
return [[[[[objc_getClass("WeatherWindSpeedFormatter") alloc] init] locale] objectForKey:NSLocaleMeasurementSystem] isEqualToString:@"Metric"];
}
- (double)windSpeedInUserUnit {
return [self usesMetricSystem] ? [self windSpeedInKiloMetersPerHour] : [self windSpeedInMilesPerHour];
}
- (NSString *)windSpeedInUserUnitString {
return [self usesMetricSystem] ? [self windSpeedInKiloMetersPerHourString] : [self windSpeedInMilesPerHourString];
}
- (double)windSpeedInUnit:(enum SpeedUnit)unit {
switch (unit) {
case SystemSpeedUnit:
return [self windSpeedInUserUnit];
case KiloMetersPerHour:
return [self windSpeedInKiloMetersPerHour];
case MilesPerHour:
return [self windSpeedInMilesPerHour];
}
}
- (NSString *)windSpeedInUnitString:(enum SpeedUnit)unit {
switch (unit) {
case SystemSpeedUnit:
return [self windSpeedInUserUnitString];
case KiloMetersPerHour:
return [self windSpeedInKiloMetersPerHourString];
case MilesPerHour:
return [self windSpeedInMilesPerHourString];
}
}
- (double)windSpeedInKiloMetersPerHour {
return round(self.windSpeed);
}
- (NSString *)windSpeedInKiloMetersPerHourString {
return [NSString stringWithFormat:@"%.0f %@", [self windSpeedInKiloMetersPerHour], @"km/h"];
}
- (double)windSpeedInMilesPerHour {
return round((self.windSpeed * 0.62137119223733));
}
- (NSString *)windSpeedInMilesPerHourString {
return [NSString stringWithFormat:@"%.0f %@", [self windSpeedInMilesPerHour], @"mph"];
}
@end