RLMConstants.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. #define RLM_HEADER_AUDIT_BEGIN NS_HEADER_AUDIT_BEGIN
  20. #define RLM_HEADER_AUDIT_END NS_HEADER_AUDIT_END
  21. #define RLM_SWIFT_SENDABLE NS_SWIFT_SENDABLE
  22. #define RLM_FINAL __attribute__((objc_subclassing_restricted))
  23. RLM_HEADER_AUDIT_BEGIN(nullability, sendability)
  24. // Swift 5 considers NS_ENUM to be "open", meaning there could be values present
  25. // other than the defined cases (which allows adding more cases later without
  26. // it being a breaking change), while older versions consider it "closed".
  27. #ifdef NS_CLOSED_ENUM
  28. #define RLM_CLOSED_ENUM NS_CLOSED_ENUM
  29. #else
  30. #define RLM_CLOSED_ENUM NS_ENUM
  31. #endif
  32. #if __has_attribute(ns_error_domain) && (!defined(__cplusplus) || !__cplusplus || __cplusplus >= 201103L)
  33. #define RLM_ERROR_ENUM(type, name, domain) \
  34. _Pragma("clang diagnostic push") \
  35. _Pragma("clang diagnostic ignored \"-Wignored-attributes\"") \
  36. NS_ENUM(type, __attribute__((ns_error_domain(domain))) name) \
  37. _Pragma("clang diagnostic pop")
  38. #else
  39. #define RLM_ERROR_ENUM(type, name, domain) NS_ENUM(type, name)
  40. #endif
  41. #define RLM_HIDDEN __attribute__((visibility("hidden")))
  42. #define RLM_VISIBLE __attribute__((visibility("default")))
  43. #define RLM_HIDDEN_BEGIN _Pragma("GCC visibility push(hidden)")
  44. #define RLM_HIDDEN_END _Pragma("GCC visibility pop")
  45. #define RLM_DIRECT __attribute__((objc_direct))
  46. #define RLM_DIRECT_MEMBERS __attribute__((objc_direct_members))
  47. #pragma mark - Enums
  48. /**
  49. `RLMPropertyType` is an enumeration describing all property types supported in Realm models.
  50. For more information, see [Realm Models](https://www.mongodb.com/docs/realm/sdk/swift/fundamentals/object-models-and-schemas/).
  51. */
  52. typedef RLM_CLOSED_ENUM(int32_t, RLMPropertyType) {
  53. #pragma mark - Primitive types
  54. /** Integers: `NSInteger`, `int`, `long`, `Int` (Swift) */
  55. RLMPropertyTypeInt = 0,
  56. /** Booleans: `BOOL`, `bool`, `Bool` (Swift) */
  57. RLMPropertyTypeBool = 1,
  58. /** Floating-point numbers: `float`, `Float` (Swift) */
  59. RLMPropertyTypeFloat = 5,
  60. /** Double-precision floating-point numbers: `double`, `Double` (Swift) */
  61. RLMPropertyTypeDouble = 6,
  62. /** NSUUID, UUID */
  63. RLMPropertyTypeUUID = 12,
  64. #pragma mark - Object types
  65. /** Strings: `NSString`, `String` (Swift) */
  66. RLMPropertyTypeString = 2,
  67. /** Binary data: `NSData` */
  68. RLMPropertyTypeData = 3,
  69. /** Any type: `id<RLMValue>`, `AnyRealmValue` (Swift) */
  70. RLMPropertyTypeAny = 9,
  71. /** Dates: `NSDate` */
  72. RLMPropertyTypeDate = 4,
  73. #pragma mark - Linked object types
  74. /** Realm model objects. See [Realm Models](https://www.mongodb.com/docs/realm/sdk/swift/fundamentals/object-models-and-schemas/) for more information. */
  75. RLMPropertyTypeObject = 7,
  76. /** Realm linking objects. See [Realm Models](https://www.mongodb.com/docs/realm/sdk/swift/fundamentals/relationships/#inverse-relationship) for more information. */
  77. RLMPropertyTypeLinkingObjects = 8,
  78. RLMPropertyTypeObjectId = 10,
  79. RLMPropertyTypeDecimal128 = 11
  80. };
  81. #pragma mark - Notification Constants
  82. /**
  83. A notification indicating that changes were made to a Realm.
  84. */
  85. typedef NSString * RLMNotification NS_EXTENSIBLE_STRING_ENUM;
  86. /**
  87. This notification is posted when a write transaction has been committed to a Realm on a different thread for
  88. the same file.
  89. It is not posted if `autorefresh` is enabled, or if the Realm is refreshed before the notification has a chance
  90. to run.
  91. Realms with autorefresh disabled should normally install a handler for this notification which calls
  92. `-[RLMRealm refresh]` after doing some work. Refreshing the Realm is optional, but not refreshing the Realm may lead to
  93. large Realm files. This is because an extra copy of the data must be kept for the stale Realm.
  94. */
  95. extern RLMNotification const RLMRealmRefreshRequiredNotification NS_SWIFT_NAME(RefreshRequired);
  96. /**
  97. This notification is posted by a Realm when a write transaction has been
  98. committed to a Realm on a different thread for the same file.
  99. It is not posted if `-[RLMRealm autorefresh]` is enabled, or if the Realm is
  100. refreshed before the notification has a chance to run.
  101. Realms with autorefresh disabled should normally install a handler for this
  102. notification which calls `-[RLMRealm refresh]` after doing some work. Refreshing
  103. the Realm is optional, but not refreshing the Realm may lead to large Realm
  104. files. This is because Realm must keep an extra copy of the data for the stale
  105. Realm.
  106. */
  107. extern RLMNotification const RLMRealmDidChangeNotification NS_SWIFT_NAME(DidChange);
  108. #pragma mark - Error keys
  109. /** Key to identify the associated backup Realm configuration in an error's `userInfo` dictionary */
  110. extern NSString * const RLMBackupRealmConfigurationErrorKey;
  111. #pragma mark - Other Constants
  112. /** The schema version used for uninitialized Realms */
  113. extern const uint64_t RLMNotVersioned;
  114. /** The corresponding value is the name of an exception thrown by Realm. */
  115. extern NSString * const RLMExceptionName;
  116. /** The corresponding value is a Realm file version. */
  117. extern NSString * const RLMRealmVersionKey;
  118. /** The corresponding key is the version of the underlying database engine. */
  119. extern NSString * const RLMRealmCoreVersionKey;
  120. /** The corresponding key is the Realm invalidated property name. */
  121. extern NSString * const RLMInvalidatedKey;
  122. RLM_HEADER_AUDIT_END(nullability, sendability)