GTLRRuntimeCommon.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Copyright (c) 2011 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #import <Foundation/Foundation.h>
  16. #import "GTLRDefines.h"
  17. @protocol GTLRObjectClassResolver;
  18. NS_ASSUME_NONNULL_BEGIN
  19. // This protocol and support class are an internal implementation detail so
  20. // GTLRObject and GTLRQuery can share some code.
  21. /**
  22. * An internal protocol for the GTLR library.
  23. *
  24. * None of these methods should be used by client apps.
  25. */
  26. @protocol GTLRRuntimeCommon <NSObject>
  27. @required
  28. // Get/Set properties
  29. - (void)setJSONValue:(nullable id)obj forKey:(NSString *)key;
  30. - (id)JSONValueForKey:(NSString *)key;
  31. // Child cache
  32. - (void)setCacheChild:(nullable id)obj forKey:(NSString *)key;
  33. - (nullable id)cacheChildForKey:(NSString *)key;
  34. // Object mapper.
  35. - (nullable id<GTLRObjectClassResolver>)objectClassResolver;
  36. // Key map
  37. + (nullable NSDictionary<NSString *, NSString *> *)propertyToJSONKeyMapForClass:(Class<GTLRRuntimeCommon>)aClass;
  38. // Array item types
  39. + (nullable NSDictionary<NSString *, Class> *)arrayPropertyToClassMapForClass:(Class<GTLRRuntimeCommon>)aClass;
  40. // The parent class for dynamic support
  41. + (nullable Class<GTLRRuntimeCommon>)ancestorClass;
  42. @end
  43. /**
  44. * An internal class for the GTLR library.
  45. *
  46. * None of these methods should be used by client apps.
  47. */
  48. @interface GTLRRuntimeCommon : NSObject
  49. // Wire things up.
  50. + (BOOL)resolveInstanceMethod:(SEL)sel onClass:(Class)onClass;
  51. // Helpers
  52. + (nullable id)objectFromJSON:(id)json
  53. defaultClass:(nullable Class)defaultClass
  54. objectClassResolver:(id<GTLRObjectClassResolver>)objectClassResolver
  55. isCacheable:(nullable BOOL *)isCacheable;
  56. + (nullable id)jsonFromAPIObject:(id)obj
  57. expectedClass:(nullable Class)expectedClass
  58. isCacheable:(nullable BOOL *)isCacheable;
  59. // Walk up the class tree merging dictionaries and return the result.
  60. + (NSDictionary *)mergedClassDictionaryForSelector:(SEL)selector
  61. startClass:(Class)startClass
  62. ancestorClass:(Class)ancestorClass
  63. cache:(NSMutableDictionary *)cache;
  64. @end
  65. NS_ASSUME_NONNULL_END