Без опису

ORKESerialization.h 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Copyright (c) 2015, Apple Inc. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without modification,
  4. are permitted provided that the following conditions are met:
  5. 1. Redistributions of source code must retain the above copyright notice, this
  6. list of conditions and the following disclaimer.
  7. 2. Redistributions in binary form must reproduce the above copyright notice,
  8. this list of conditions and the following disclaimer in the documentation and/or
  9. other materials provided with the distribution.
  10. 3. Neither the name of the copyright holder(s) nor the names of any contributors
  11. may be used to endorse or promote products derived from this software without
  12. specific prior written permission. No license is granted to the trademarks of
  13. the copyright holders even if such marks are included in this software.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  15. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  18. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  20. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  21. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  22. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. @import Foundation;
  26. NS_ASSUME_NONNULL_BEGIN
  27. typedef _Nullable id (^ORKESerializationPropertyGetter)(NSDictionary *dict, NSString *property);
  28. typedef _Nullable id (^ORKESerializationInitBlock)(NSDictionary *dict, ORKESerializationPropertyGetter getter);
  29. typedef _Nullable id (^ORKESerializationObjectToJSONBlock)(id object);
  30. typedef _Nullable id (^ORKESerializationJSONToObjectBlock)(id jsonObject);
  31. @interface ORKESerializationLocalizer : NSObject
  32. - (instancetype)initWithBundle:(NSBundle *)bundle tableName:(NSString *)tableName;
  33. @property (nonatomic, strong) NSBundle *bundle;
  34. @property (nonatomic, strong) NSString *tableName;
  35. @end
  36. @interface ORKESerializer : NSObject
  37. + (nullable NSDictionary *)JSONObjectForObject:(id)object error:(NSError **)error;
  38. + (nullable NSData *)JSONDataForObject:(id)object error:(NSError **)error;
  39. + (nullable id)objectFromJSONObject:(NSDictionary *)object error:(NSError **)error;
  40. + (nullable id)objectFromJSONObject:(NSDictionary *)object localizer:(ORKESerializationLocalizer *)localizer error:(NSError **)error;
  41. + (nullable id)objectFromJSONData:(NSData *)data error:(NSError **)error;
  42. + (NSArray *)serializableClasses;
  43. @end
  44. @interface ORKESerializer (Registration)
  45. + (void)registerSerializableClass:(Class)serializableClass
  46. initBlock:(nullable ORKESerializationInitBlock)initBlock;
  47. + (void)registerSerializableClassPropertyName:(NSString *)propertyName
  48. forClass:(Class)serializableClass
  49. valueClass:(Class)valueClass
  50. containerClass:(nullable Class)containerClass
  51. writeAfterInit:(BOOL)writeAfterInit
  52. objectToJSONBlock:(nullable ORKESerializationObjectToJSONBlock)objectToJSON
  53. jsonToObjectBlock:(nullable ORKESerializationJSONToObjectBlock)jsonToObjectBlock;
  54. @end
  55. NS_ASSUME_NONNULL_END