RLMRealm_Dynamic.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 <Realm/RLMRealm.h>
  19. #import <Realm/RLMObjectSchema.h>
  20. #import <Realm/RLMProperty.h>
  21. @class RLMResults<RLMObjectType>;
  22. NS_ASSUME_NONNULL_BEGIN
  23. @interface RLMRealm (Dynamic)
  24. #pragma mark - Getting Objects from a Realm
  25. /**
  26. Returns all objects of a given type from the Realm.
  27. @warning This method is useful only in specialized circumstances, for example, when building components
  28. that integrate with Realm. The preferred way to get objects of a single class is to use the class
  29. methods on `RLMObject`.
  30. @param className The name of the `RLMObject` subclass to retrieve on (e.g. `MyClass.className`).
  31. @return An `RLMResults` containing all objects in the Realm of the given type.
  32. @see `+[RLMObject allObjects]`
  33. */
  34. - (RLMResults<RLMObject *> *)allObjects:(NSString *)className;
  35. /**
  36. Returns all objects matching the given predicate from the Realm.
  37. @warning This method is useful only in specialized circumstances, for example, when building components
  38. that integrate with Realm. The preferred way to get objects of a single class is to use the class
  39. methods on `RLMObject`.
  40. @param className The type of objects you are looking for (name of the class).
  41. @param predicateFormat A predicate format string, optionally followed by a variable number of arguments.
  42. @return An `RLMResults` containing results matching the given predicate.
  43. @see `+[RLMObject objectsWhere:]`
  44. */
  45. - (RLMResults<RLMObject *> *)objects:(NSString *)className where:(NSString *)predicateFormat, ...;
  46. /**
  47. Returns all objects matching the given predicate from the Realm.
  48. @warning This method is useful only in specialized circumstances, for example, when building components
  49. that integrate with Realm. The preferred way to get objects of a single class is to use the class
  50. methods on `RLMObject`.
  51. @param className The type of objects you are looking for (name of the class).
  52. @param predicate The predicate with which to filter the objects.
  53. @return An `RLMResults` containing results matching the given predicate.
  54. @see `+[RLMObject objectsWhere:]`
  55. */
  56. - (RLMResults<RLMObject *> *)objects:(NSString *)className withPredicate:(NSPredicate *)predicate;
  57. /**
  58. Returns the object of the given type with the given primary key from the Realm.
  59. @warning This method is useful only in specialized circumstances, for example, when building components
  60. that integrate with Realm. The preferred way to get an object of a single class is to use the class
  61. methods on `RLMObject`.
  62. @param className The class name for the object you are looking for.
  63. @param primaryKey The primary key value for the object you are looking for.
  64. @return An object, or `nil` if an object with the given primary key does not exist.
  65. @see `+[RLMObject objectForPrimaryKey:]`
  66. */
  67. - (nullable RLMObject *)objectWithClassName:(NSString *)className forPrimaryKey:(id)primaryKey;
  68. /**
  69. Creates an `RLMObject` instance of type `className` in the Realm, and populates it using a given object.
  70. The `value` argument is used to populate the object. It can be a key-value coding compliant object, an array or
  71. dictionary returned from the methods in `NSJSONSerialization`, or an array containing one element for each managed
  72. property. An exception will be thrown if any required properties are not present and those properties were not defined
  73. with default values.
  74. When passing in an array as the `value` argument, all properties must be present, valid and in the same order as the
  75. properties defined in the model.
  76. @warning This method is useful only in specialized circumstances, for example, when building components
  77. that integrate with Realm. If you are simply building an app on Realm, it is recommended to
  78. use `[RLMObject createInDefaultRealmWithValue:]`.
  79. @param value The value used to populate the object.
  80. @return An `RLMObject` instance of type `className`.
  81. */
  82. -(RLMObject *)createObject:(NSString *)className withValue:(id)value;
  83. @end
  84. NS_ASSUME_NONNULL_END