feat: Handle weather code as nullable parameter

This commit is contained in:
Andrea Busi
2020-10-03 12:01:17 +02:00
parent e194731bc8
commit ba2fbfaa60
4 changed files with 16 additions and 2 deletions
@@ -16,6 +16,10 @@ NS_ASSUME_NONNULL_BEGIN
/// @param prettyPrint If YES, uses white space and indentation to make the output more readable.
- (NSString *)eqn_jsonStringWithPrettyPrint:(BOOL)prettyPrint;
/// Returns the value associated with a given key if exists, nil otherwise.
/// @param aKey The key for which to return the corresponding value
- (nullable id)eqn_safeObjectForKey:(id)aKey;
@end
NS_ASSUME_NONNULL_END
@@ -24,4 +24,13 @@
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
- (id)eqn_safeObjectForKey:(id)aKey
{
NSObject *object = [self objectForKey:aKey];
if (object == [NSNull null]) {
return nil;
}
return object;
}
@end
+1 -1
View File
@@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong) NSNumber *preliminary;
@property (nonatomic, strong) NSNumber *smartphoneNumber;
@property (nonatomic, strong) NSNumber *userNumber;
@property (nonatomic, strong) NSString *weatherCode;
@property (nonatomic, strong, nullable) NSString *weatherCode;
@property (nonatomic, strong) NSString *weatherIcon;
@property (nonatomic, strong) NSNumber *weatherCloud;
@property (nonatomic, strong) NSNumber *weatherWindSpeed;
+2 -1
View File
@@ -9,6 +9,7 @@
#import "EQNSisma.h"
#import "EQNUser.h"
#import "EQNUtility.h"
#import "NSDictionary+EQNExtensions.h"
@implementation EQNSisma
@@ -42,7 +43,7 @@
self.smartphoneNumber = info[@"sm"];
self.userNumber = info[@"rp"];
self.weatherCode = info[@"wc"];
self.weatherCode = [info eqn_safeObjectForKey:@"wc"];
self.weatherIcon = info[@"ic"];
self.weatherCloud = info[@"cl"];
self.weatherWindSpeed = info[@"ws"];