RLMConstants.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 models with any-typed properties are still
  60. supported for migration purposes.
  61. */
  62. RLMPropertyTypeAny = 9,
  63. /** Dates: `NSDate` */
  64. RLMPropertyTypeDate = 4,
  65. #pragma mark - Array/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 arrays. See [Realm Models](https://realm.io/docs/objc/latest/#models) for more information. */
  69. RLMPropertyTypeArray = 128,
  70. /** Realm linking objects. See [Realm Models](https://realm.io/docs/objc/latest/#models) for more information. */
  71. RLMPropertyTypeLinkingObjects = 8,
  72. };
  73. /** An error domain identifying Realm-specific errors. */
  74. extern NSString * const RLMErrorDomain;
  75. /** An error domain identifying non-specific system errors. */
  76. extern NSString * const RLMUnknownSystemErrorDomain;
  77. /**
  78. `RLMError` is an enumeration representing all recoverable errors. It is associated with the
  79. Realm error domain specified in `RLMErrorDomain`.
  80. */
  81. typedef RLM_ERROR_ENUM(NSInteger, RLMError, RLMErrorDomain) {
  82. /** Denotes a general error that occurred when trying to open a Realm. */
  83. RLMErrorFail = 1,
  84. /** Denotes a file I/O error that occurred when trying to open a Realm. */
  85. RLMErrorFileAccess = 2,
  86. /**
  87. Denotes a file permission error that ocurred when trying to open a Realm.
  88. This error can occur if the user does not have permission to open or create
  89. the specified file in the specified access mode when opening a Realm.
  90. */
  91. RLMErrorFilePermissionDenied = 3,
  92. /** Denotes an error where a file was to be written to disk, but another file with the same name already exists. */
  93. RLMErrorFileExists = 4,
  94. /**
  95. Denotes an error that occurs if a file could not be found.
  96. This error may occur if a Realm file could not be found on disk when trying to open a
  97. Realm as read-only, or if the directory part of the specified path was not found when
  98. trying to write a copy.
  99. */
  100. RLMErrorFileNotFound = 5,
  101. /**
  102. Denotes an error that occurs if a file format upgrade is required to open the file,
  103. but upgrades were explicitly disabled.
  104. */
  105. RLMErrorFileFormatUpgradeRequired = 6,
  106. /**
  107. Denotes an error that occurs if the database file is currently open in another
  108. process which cannot share with the current process due to an
  109. architecture mismatch.
  110. This error may occur if trying to share a Realm file between an i386 (32-bit) iOS
  111. Simulator and the Realm Browser application. In this case, please use the 64-bit
  112. version of the iOS Simulator.
  113. */
  114. RLMErrorIncompatibleLockFile = 8,
  115. /** Denotes an error that occurs when there is insufficient available address space. */
  116. RLMErrorAddressSpaceExhausted = 9,
  117. /** Denotes an error that occurs if there is a schema version mismatch, so that a migration is required. */
  118. RLMErrorSchemaMismatch = 10,
  119. };
  120. #pragma mark - Constants
  121. #pragma mark - Notification Constants
  122. /**
  123. A notification indicating that changes were made to a Realm.
  124. */
  125. typedef NSString * RLMNotification RLM_EXTENSIBLE_STRING_ENUM;
  126. /**
  127. This notification is posted by a Realm when the data in that Realm has changed.
  128. More specifically, this notification is posted after a Realm has been refreshed to
  129. reflect a write transaction. This can happen when an autorefresh occurs, when
  130. `-[RLMRealm refresh]` is called, after an implicit refresh from `-[RLMRealm beginWriteTransaction]`,
  131. or after a local write transaction is completed.
  132. */
  133. extern RLMNotification const RLMRealmRefreshRequiredNotification
  134. RLM_EXTENSIBLE_STRING_ENUM_CASE_SWIFT_NAME(RLMRealmRefreshRequiredNotification, RefreshRequired);
  135. /**
  136. This notification is posted by a Realm when a write transaction has been
  137. committed to a Realm on a different thread for the same file.
  138. It is not posted if `-[RLMRealm autorefresh]` is enabled, or if the Realm is
  139. refreshed before the notification has a chance to run.
  140. Realms with autorefresh disabled should normally install a handler for this
  141. notification which calls `-[RLMRealm refresh]` after doing some work. Refreshing
  142. the Realm is optional, but not refreshing the Realm may lead to large Realm
  143. files. This is because Realm must keep an extra copy of the data for the stale
  144. Realm.
  145. */
  146. extern RLMNotification const RLMRealmDidChangeNotification
  147. RLM_EXTENSIBLE_STRING_ENUM_CASE_SWIFT_NAME(RLMRealmDidChangeNotification, DidChange);
  148. #pragma mark - Other Constants
  149. /** The schema version used for uninitialized Realms */
  150. extern const uint64_t RLMNotVersioned;
  151. /** The corresponding value is the name of an exception thrown by Realm. */
  152. extern NSString * const RLMExceptionName;
  153. /** The corresponding value is a Realm file version. */
  154. extern NSString * const RLMRealmVersionKey;
  155. /** The corresponding key is the version of the underlying database engine. */
  156. extern NSString * const RLMRealmCoreVersionKey;
  157. /** The corresponding key is the Realm invalidated property name. */
  158. extern NSString * const RLMInvalidatedKey;
  159. NS_ASSUME_NONNULL_END