RLMObjectStore.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. @class RLMRealm, RLMSchema, RLMObjectBase, RLMResults, RLMProperty;
  23. NS_ASSUME_NONNULL_BEGIN
  24. //
  25. // Accessor Creation
  26. //
  27. // create or get cached accessors for the given schema
  28. void RLMRealmCreateAccessors(RLMSchema *schema);
  29. //
  30. // Options for object creation
  31. //
  32. typedef NS_OPTIONS(NSUInteger, RLMCreationOptions) {
  33. // Normal object creation
  34. RLMCreationOptionsNone = 0,
  35. // If the property is a link or array property, upsert the linked objects
  36. // if they have a primary key, and insert them otherwise.
  37. RLMCreationOptionsCreateOrUpdate = 1 << 0,
  38. // Allow unmanaged objects to be promoted to managed objects
  39. // if false objects are copied during object creation
  40. RLMCreationOptionsPromoteUnmanaged = 1 << 1,
  41. // Use the SetDefault instruction.
  42. RLMCreationOptionsSetDefault = 1 << 2,
  43. };
  44. //
  45. // Adding, Removing, Getting Objects
  46. //
  47. // add an object to the given realm
  48. void RLMAddObjectToRealm(RLMObjectBase *object, RLMRealm *realm, bool createOrUpdate);
  49. // delete an object from its realm
  50. void RLMDeleteObjectFromRealm(RLMObjectBase *object, RLMRealm *realm);
  51. // deletes all objects from a realm
  52. void RLMDeleteAllObjectsFromRealm(RLMRealm *realm);
  53. // get objects of a given class
  54. RLMResults *RLMGetObjects(RLMRealm *realm, NSString *objectClassName, NSPredicate * _Nullable predicate)
  55. NS_RETURNS_RETAINED;
  56. // get an object with the given primary key
  57. id _Nullable RLMGetObject(RLMRealm *realm, NSString *objectClassName, id _Nullable key) NS_RETURNS_RETAINED;
  58. // create object from array or dictionary
  59. RLMObjectBase *RLMCreateObjectInRealmWithValue(RLMRealm *realm, NSString *className, id _Nullable value, bool createOrUpdate)
  60. NS_RETURNS_RETAINED;
  61. //
  62. // Accessor Creation
  63. //
  64. // switch List<> properties from being backed by unmanaged RLMArrays to RLMArrayLinkView
  65. void RLMInitializeSwiftAccessorGenerics(RLMObjectBase *object);
  66. #ifdef __cplusplus
  67. }
  68. namespace realm {
  69. class Table;
  70. template<typename T> class BasicRowExpr;
  71. using RowExpr = BasicRowExpr<Table>;
  72. }
  73. class RLMClassInfo;
  74. // Create accessors
  75. RLMObjectBase *RLMCreateObjectAccessor(RLMRealm *realm, RLMClassInfo& info,
  76. NSUInteger index) NS_RETURNS_RETAINED;
  77. RLMObjectBase *RLMCreateObjectAccessor(RLMRealm *realm, RLMClassInfo& info,
  78. realm::RowExpr row) NS_RETURNS_RETAINED;
  79. #endif
  80. NS_ASSUME_NONNULL_END