Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/*
2
 * Copyright 2019 Google
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
 
17
#import "FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h"
18
 
19
#import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
20
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
21
 
22
@implementation FIRRemoteConfigValue {
23
  /// Data backing the config value.
24
  NSData *_data;
25
  FIRRemoteConfigSource _source;
26
}
27
 
28
/// Designated initializer
29
- (instancetype)initWithData:(NSData *)data source:(FIRRemoteConfigSource)source {
30
  self = [super init];
31
  if (self) {
32
    _data = [data copy];
33
    _source = source;
34
  }
35
  return self;
36
}
37
 
38
/// Superclass's designated initializer
39
- (instancetype)init {
40
  return [self initWithData:nil source:FIRRemoteConfigSourceStatic];
41
}
42
 
43
/// The string is a UTF-8 representation of NSData.
44
- (NSString *)stringValue {
45
  return [[NSString alloc] initWithData:_data encoding:NSUTF8StringEncoding];
46
}
47
 
48
/// Number representation of a UTF-8 string.
49
- (NSNumber *)numberValue {
50
  return [NSNumber numberWithDouble:self.stringValue.doubleValue];
51
}
52
 
53
/// Internal representation of the FIRRemoteConfigValue as a NSData object.
54
- (NSData *)dataValue {
55
  return _data;
56
}
57
 
58
/// Boolean representation of a UTF-8 string.
59
- (BOOL)boolValue {
60
  return self.stringValue.boolValue;
61
}
62
 
63
/// Returns a foundation object (NSDictionary / NSArray) representation for JSON data.
64
- (id)JSONValue {
65
  NSError *error;
66
  if (!_data) {
67
    return nil;
68
  }
69
  id JSONObject = [NSJSONSerialization JSONObjectWithData:_data options:kNilOptions error:&error];
70
  if (error) {
71
    FIRLogDebug(kFIRLoggerRemoteConfig, @"I-RCN000065", @"Error parsing data as JSON.");
72
    return nil;
73
  }
74
  return JSONObject;
75
}
76
 
77
/// Debug description showing the representations of all types.
78
- (NSString *)debugDescription {
79
  NSString *content = [NSString
80
      stringWithFormat:@"Boolean: %d, String: %@, Number: %@, JSON:%@, Data: %@, Source: %zd",
81
                       self.boolValue, self.stringValue, self.numberValue, self.JSONValue, _data,
82
                       (long)self.source];
83
  return [NSString stringWithFormat:@"<%@: %p, %@>", [self class], self, content];
84
}
85
 
86
/// Copy method.
87
- (id)copyWithZone:(NSZone *)zone {
88
  FIRRemoteConfigValue *value = [[[self class] allocWithZone:zone] initWithData:_data];
89
  return value;
90
}
91
@end