Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/*
2
 * Copyright 2017 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 "FirebaseMessaging/Sources/NSDictionary+FIRMessaging.h"
18
 
19
@implementation NSDictionary (FIRMessaging)
20
 
21
- (NSString *)fcm_string {
22
  NSMutableString *dictAsString = [NSMutableString string];
23
  NSString *separator = @"|";
24
  for (id key in self) {
25
    id value = self[key];
26
    if ([key isKindOfClass:[NSString class]] && [value isKindOfClass:[NSString class]]) {
27
      [dictAsString appendFormat:@"%@:%@%@", key, value, separator];
28
    }
29
  }
30
  // remove the last separator
31
  if ([dictAsString length]) {
32
    [dictAsString deleteCharactersInRange:NSMakeRange(dictAsString.length - 1, 1)];
33
  }
34
  return [dictAsString copy];
35
}
36
 
37
- (BOOL)fcm_hasNonStringKeysOrValues {
38
  for (id key in self) {
39
    id value = self[key];
40
    if (![key isKindOfClass:[NSString class]] || ![value isKindOfClass:[NSString class]]) {
41
      return YES;
42
    }
43
  }
44
  return NO;
45
}
46
 
47
- (NSDictionary *)fcm_trimNonStringValues {
48
  NSMutableDictionary *trimDictionary = [NSMutableDictionary dictionaryWithCapacity:self.count];
49
  for (id key in self) {
50
    id value = self[key];
51
    if ([key isKindOfClass:[NSString class]] && [value isKindOfClass:[NSString class]]) {
52
      trimDictionary[(NSString *)key] = value;
53
    }
54
  }
55
  return trimDictionary;
56
}
57
 
58
@end