react-native-navigation的迁移库

RNNUtils.m 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #import "RNNUtils.h"
  2. @implementation RNNUtils
  3. +(double)getDoubleOrKey:(NSDictionary*)dict withKey:(NSString*)key withDefault:(double)defaultResult {
  4. if ([dict objectForKey:key]) {
  5. return [dict[key] doubleValue];
  6. } else {
  7. return defaultResult;
  8. }
  9. }
  10. +(BOOL)getBoolOrKey:(NSDictionary*)dict withKey:(NSString*)key withDefault:(BOOL)defaultResult {
  11. if ([dict objectForKey:key]) {
  12. return [dict[key] boolValue];
  13. } else {
  14. return defaultResult;
  15. }
  16. }
  17. +(id)getObjectOrKey:(NSDictionary*)dict withKey:(NSString*)key withDefault:(id)defaultResult {
  18. if ([dict objectForKey:key]) {
  19. return dict[key];
  20. } else {
  21. return defaultResult;
  22. }
  23. }
  24. + (NSNumber *)getCurrentTimestamp {
  25. return [NSNumber numberWithLong:[[NSDate date] timeIntervalSince1970] * 1000];
  26. }
  27. BOOL RNNIsMainQueue() {
  28. static void *mainQueueKey = &mainQueueKey;
  29. static dispatch_once_t onceToken;
  30. dispatch_once(&onceToken, ^{
  31. dispatch_queue_set_specific(dispatch_get_main_queue(),
  32. mainQueueKey, mainQueueKey, NULL);
  33. });
  34. return dispatch_get_specific(mainQueueKey) == mainQueueKey;
  35. }
  36. @end