RLMConstants.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. NS_ASSUME_NONNULL_BEGIN
  20. // For compatibility with Xcode 7, before extensible string enums were introduced,
  21. #ifdef NS_EXTENSIBLE_STRING_ENUM
  22. #define RLM_EXTENSIBLE_STRING_ENUM NS_EXTENSIBLE_STRING_ENUM
  23. #define RLM_EXTENSIBLE_STRING_ENUM_CASE_SWIFT_NAME(_, extensible_string_enum) NS_SWIFT_NAME(extensible_string_enum)
  24. #else
  25. #define RLM_EXTENSIBLE_STRING_ENUM
  26. #define RLM_EXTENSIBLE_STRING_ENUM_CASE_SWIFT_NAME(fully_qualified, _) NS_SWIFT_NAME(fully_qualified)
  27. #endif
  28. // Swift 5 considers NS_ENUM to be "open", meaning there could be values present
  29. // other than the defined cases (which allows adding more cases later without
  30. // it being a breaking change), while older versions consider it "closed".
  31. #ifdef NS_CLOSED_ENUM
  32. #define RLM_CLOSED_ENUM NS_CLOSED_ENUM
  33. #else
  34. #define RLM_CLOSED_ENUM NS_ENUM
  35. #endif
  36. #if __has_attribute(ns_error_domain) && (!defined(__cplusplus) || !__cplusplus || __cplusplus >= 201103L)
  37. #define RLM_ERROR_ENUM(type, name, domain) \
  38. _Pragma("clang diagnostic push") \
  39. _Pragma("clang diagnostic ignored \"-Wignored-attributes\"") \
  40. NS_ENUM(type, __attribute__((ns_error_domain(domain))) name) \
  41. _Pragma("clang diagnostic pop")
  42. #else
  43. #define RLM_ERROR_ENUM(type, name, domain) NS_ENUM(type, name)
  44. #endif
  45. #pragma mark - Enums
  46. /**
  47. `RLMPropertyType` is an enumeration describing all property types supported in Realm models.
  48. For more information, see [Realm Models](https://realm.io/docs/objc/latest/#models).
  49. */
  50. typedef RLM_CLOSED_ENUM(int32_t, RLMPropertyType) {
  51. #pragma mark - Primitive types
  52. /** Integers: `NSInteger`, `int`, `long`, `Int` (Swift) */
  53. RLMPropertyTypeInt = 0,
  54. /** Booleans: `BOOL`, `bool`, `Bool` (Swift) */
  55. RLMPropertyTypeBool = 1,
  56. /** Floating-point numbers: `float`, `Float` (Swift) */
  57. RLMPropertyTypeFloat = 5,
  58. /** Double-precision floating-point numbers: `double`, `Double` (Swift) */
  59. RLMPropertyTypeDouble = 6,
  60. #pragma mark - Object types
  61. /** Strings: `NSString`, `String` (Swift) */
  62. RLMPropertyTypeString = 2,
  63. /** Binary data: `NSData` */
  64. RLMPropertyTypeData = 3,
  65. /**
  66. Any object: `id`.
  67. This property type is no longer supported for new models. However, old files
  68. with any-typed properties are still supported for migration purposes.
  69. */
  70. RLMPropertyTypeAny = 9,
  71. /** Dates: `NSDate` */
  72. RLMPropertyTypeDate = 4,
  73. #pragma mark - Linked object types
  74. /** Realm model objects. See [Realm Models](https://realm.io/docs/objc/latest/#models) for more information. */
  75. RLMPropertyTypeObject = 7,
  76. /** Realm linking objects. See [Realm Models](https://realm.io/docs/objc/latest/#models) for more information. */
  77. RLMPropertyTypeLinkingObjects = 8,
  78. };
  79. /** An error domain identifying Realm-specific errors. */
  80. extern NSString * const RLMErrorDomain;
  81. /** An error domain identifying non-specific system errors. */
  82. extern NSString * const RLMUnknownSystemErrorDomain;
  83. /**
  84. `RLMError` is an enumeration representing all recoverable errors. It is associated with the
  85. Realm error domain specified in `RLMErrorDomain`.
  86. */
  87. typedef RLM_ERROR_ENUM(NSInteger, RLMError, RLMErrorDomain) {
  88. /** Denotes a general error that occurred when trying to open a Realm. */
  89. RLMErrorFail = 1,
  90. /** Denotes a file I/O error that occurred when trying to open a Realm. */
  91. RLMErrorFileAccess = 2,
  92. /**
  93. Denotes a file permission error that ocurred when trying to open a Realm.
  94. This error can occur if the user does not have permission to open or create
  95. the specified file in the specified access mode when opening a Realm.
  96. */
  97. RLMErrorFilePermissionDenied = 3,
  98. /** Denotes an error where a file was to be written to disk, but another file with the same name already exists. */
  99. RLMErrorFileExists = 4,
  100. /**
  101. Denotes an error that occurs if a file could not be found.
  102. This error may occur if a Realm file could not be found on disk when trying to open a
  103. Realm as read-only, or if the directory part of the specified path was not found when
  104. trying to write a copy.
  105. */
  106. RLMErrorFileNotFound = 5,
  107. /**
  108. Denotes an error that occurs if a file format upgrade is required to open the file,
  109. but upgrades were explicitly disabled.
  110. */
  111. RLMErrorFileFormatUpgradeRequired = 6,
  112. /**
  113. Denotes an error that occurs if the database file is currently open in another
  114. process which cannot share with the current process due to an
  115. architecture mismatch.
  116. This error may occur if trying to share a Realm file between an i386 (32-bit) iOS
  117. Simulator and the Realm Browser application. In this case, please use the 64-bit
  118. version of the iOS Simulator.
  119. */
  120. RLMErrorIncompatibleLockFile = 8,
  121. /** Denotes an error that occurs when there is insufficient available address space. */
  122. RLMErrorAddressSpaceExhausted = 9,
  123. /** Denotes an error that occurs if there is a schema version mismatch, so that a migration is required. */
  124. RLMErrorSchemaMismatch = 10,
  125. /** Denotes an error that occurs when attempting to open an incompatible synchronized Realm file.
  126. This error occurs when the Realm file was created with an older version of Realm and an automatic migration
  127. to the current version is not possible. When such an error occurs, the original file is moved to a backup
  128. location, and future attempts to open the synchronized Realm will result in a new file being created.
  129. If you wish to migrate any data from the backup Realm, you can open it using the provided Realm configuration.
  130. */
  131. RLMErrorIncompatibleSyncedFile = 11,
  132. /**
  133. Denotates an error where an operation was requested which cannot be performed on an open file.
  134. */
  135. RLMErrorAlreadyOpen = 12,
  136. };
  137. #pragma mark - Constants
  138. #pragma mark - Notification Constants
  139. /**
  140. A notification indicating that changes were made to a Realm.
  141. */
  142. typedef NSString * RLMNotification RLM_EXTENSIBLE_STRING_ENUM;
  143. /**
  144. This notification is posted when a write transaction has been committed to a Realm on a different thread for
  145. the same file.
  146. It is not posted if `autorefresh` is enabled, or if the Realm is refreshed before the notification has a chance
  147. to run.
  148. Realms with autorefresh disabled should normally install a handler for this notification which calls
  149. `-[RLMRealm refresh]` after doing some work. Refreshing the Realm is optional, but not refreshing the Realm may lead to
  150. large Realm files. This is because an extra copy of the data must be kept for the stale Realm.
  151. */
  152. extern RLMNotification const RLMRealmRefreshRequiredNotification
  153. RLM_EXTENSIBLE_STRING_ENUM_CASE_SWIFT_NAME(RLMRealmRefreshRequiredNotification, RefreshRequired);
  154. /**
  155. This notification is posted by a Realm when a write transaction has been
  156. committed to a Realm on a different thread for the same file.
  157. It is not posted if `-[RLMRealm autorefresh]` is enabled, or if the Realm is
  158. refreshed before the notification has a chance to run.
  159. Realms with autorefresh disabled should normally install a handler for this
  160. notification which calls `-[RLMRealm refresh]` after doing some work. Refreshing
  161. the Realm is optional, but not refreshing the Realm may lead to large Realm
  162. files. This is because Realm must keep an extra copy of the data for the stale
  163. Realm.
  164. */
  165. extern RLMNotification const RLMRealmDidChangeNotification
  166. RLM_EXTENSIBLE_STRING_ENUM_CASE_SWIFT_NAME(RLMRealmDidChangeNotification, DidChange);
  167. #pragma mark - Error keys
  168. /** Key to identify the associated backup Realm configuration in an error's `userInfo` dictionary */
  169. extern NSString * const RLMBackupRealmConfigurationErrorKey;
  170. #pragma mark - Other Constants
  171. /** The schema version used for uninitialized Realms */
  172. extern const uint64_t RLMNotVersioned;
  173. /** The corresponding value is the name of an exception thrown by Realm. */
  174. extern NSString * const RLMExceptionName;
  175. /** The corresponding value is a Realm file version. */
  176. extern NSString * const RLMRealmVersionKey;
  177. /** The corresponding key is the version of the underlying database engine. */
  178. extern NSString * const RLMRealmCoreVersionKey;
  179. /** The corresponding key is the Realm invalidated property name. */
  180. extern NSString * const RLMInvalidatedKey;
  181. NS_ASSUME_NONNULL_END