RLMConstants.h 8.2 KB

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