DataModels.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2014 Realm Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. #import <Foundation/Foundation.h>
  19. #import <Realm/Realm.h>
  20. // Old data models
  21. /* V0
  22. @interface Person : RLMObject
  23. @property NSString *firstName;
  24. @property NSString *lastName;
  25. @property int age;
  26. @end
  27. */
  28. /* V1
  29. @interface Person : RLMObject
  30. @property NSString *fullName; // combine firstName and lastName into single field
  31. @property int age;
  32. @end
  33. */
  34. /* V2
  35. @interface Pet : RLMObject // add a new model class
  36. @property NSString *name;
  37. @property NSString *type;
  38. @end
  39. RLM_ARRAY_TYPE(Pet)
  40. @interface Person : RLMObject
  41. @property NSString *fullName;
  42. @property RLMArray<Pet> *pets; // add and array property
  43. @property int age;
  44. @end
  45. */
  46. /* V3 */
  47. typedef NS_ENUM(NSInteger, AnimalType) {
  48. AnimalTypeDog = 1,
  49. AnimalTypeCat,
  50. AnimalTypeHamster,
  51. };
  52. @interface Pet : RLMObject
  53. @property NSString *name;
  54. @property AnimalType type; // change type from string to enum
  55. + (AnimalType)animalTypeForString:(NSString *)typeString;
  56. @end
  57. RLM_ARRAY_TYPE(Pet)
  58. @interface Person : RLMObject
  59. @property NSString *fullName;
  60. @property int age; // age and pets properties re-ordered (handled automatically)
  61. @property RLMArray<Pet> *pets;
  62. @end