Blame view

Pods/Realm/include/RLMObject.h 35 KB
75d24c15   yangbin   123
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
  ////////////////////////////////////////////////////////////////////////////
  //
  // Copyright 2014 Realm Inc.
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  // http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  //
  ////////////////////////////////////////////////////////////////////////////
  
  #import <Foundation/Foundation.h>
  
  #import <Realm/RLMObjectBase.h>
  #import <Realm/RLMThreadSafeReference.h>
  
  NS_ASSUME_NONNULL_BEGIN
  
  @class RLMNotificationToken;
  @class RLMObjectSchema;
  @class RLMPropertyChange;
  @class RLMPropertyDescriptor;
  @class RLMRealm;
  @class RLMResults<RLMObjectType>;
  
  /**
   `RLMObject` is a base class for model objects representing data stored in Realms.
  
   Define your model classes by subclassing `RLMObject` and adding properties to be managed.
   Then instantiate and use your custom subclasses instead of using the `RLMObject` class directly.
  
       // Dog.h
       @interface Dog : RLMObject
       @property NSString *name;
       @property BOOL      adopted;
       @end
  
       // Dog.m
       @implementation Dog
       @end //none needed
  
   ### Supported property types
  
   - `NSString`
   - `NSInteger`, `int`, `long`, `float`, and `double`
   - `BOOL` or `bool`
   - `NSDate`
   - `NSData`
   - `NSNumber<X>`, where `X` is one of `RLMInt`, `RLMFloat`, `RLMDouble` or `RLMBool`, for optional number properties
   - `RLMObject` subclasses, to model many-to-one relationships.
   - `RLMArray<X>`, where `X` is an `RLMObject` subclass, to model many-to-many relationships.
  
   ### Querying
  
   You can initiate queries directly via the class methods: `allObjects`, `objectsWhere:`, and `objectsWithPredicate:`.
   These methods allow you to easily query a custom subclass for instances of that class in the default Realm.
  
   To search in a Realm other than the default Realm, use the `allObjectsInRealm:`, `objectsInRealm:where:`,
   and `objectsInRealm:withPredicate:` class methods.
  
   @see `RLMRealm`
  
   ### Relationships
  
   See our [Cocoa guide](https://realm.io/docs/objc/latest#relationships) for more details.
  
   ### Key-Value Observing
  
   All `RLMObject` properties (including properties you create in subclasses) are
   [Key-Value Observing compliant](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html),
   except for `realm` and `objectSchema`.
  
   Keep the following tips in mind when observing Realm objects:
  
   1. Unlike `NSMutableArray` properties, `RLMArray` properties do not require
      using the proxy object returned from `-mutableArrayValueForKey:`, or defining
      KVC mutation methods on the containing class. You can simply call methods on
      the `RLMArray` directly; any changes will be automatically observed by the containing
      object.
   2. Unmanaged `RLMObject` instances cannot be added to a Realm while they have any
      observed properties.
   3. Modifying managed `RLMObject`s within `-observeValueForKeyPath:ofObject:change:context:`
      is not recommended. Properties may change even when the Realm is not in a write
      transaction (for example, when `-[RLMRealm refresh]` is called after changes
      are made on a different thread), and notifications sent prior to the change
      being applied (when `NSKeyValueObservingOptionPrior` is used) may be sent at
      times when you *cannot* begin a write transaction.
   */
  
  @interface RLMObject : RLMObjectBase <RLMThreadConfined>
  
  #pragma mark - Creating & Initializing Objects
  
  /**
   Creates an unmanaged instance of a Realm object.
  
   Call `addObject:` on an `RLMRealm` instance to add an unmanaged object into that Realm.
  
   @see `[RLMRealm addObject:]`
   */
  - (instancetype)init NS_DESIGNATED_INITIALIZER;
  
  
  /**
   Creates an unmanaged instance of a Realm object.
  
   Pass in an `NSArray` or `NSDictionary` instance to set the values of the object's properties.
  
   Call `addObject:` on an `RLMRealm` instance to add an unmanaged object into that Realm.
  
   @see `[RLMRealm addObject:]`
   */
  - (instancetype)initWithValue:(id)value;
  
  
  /**
   Returns the class name for a Realm object subclass.
  
   @warning Do not override. Realm relies on this method returning the exact class
            name.
  
   @return  The class name for the model class.
   */
  + (NSString *)className;
  
  /**
   Creates an instance of a Realm object with a given value, and adds it to the default Realm.
  
   If nested objects are included in the argument, `createInDefaultRealmWithValue:` will be recursively called
   on them.
  
   The `value` argument can be a key-value coding compliant object, an array or dictionary returned from the methods in
   `NSJSONSerialization`, or an array containing one element for each managed property.
  
   An exception will be thrown if any required properties are not present and those properties
   were not defined with default values.
  
   If the `value` argument is an array, all properties must be present, valid and in the same
   order as the properties defined in the model.
  
   @param value    The value used to populate the object.
  
   @see   `defaultPropertyValues`
   */
  + (instancetype)createInDefaultRealmWithValue:(id)value;
  
  /**
   Creates an instance of a Realm object with a given value, and adds it to the specified Realm.
  
   If nested objects are included in the argument, `createInRealm:withValue:` will be recursively called
   on them.
  
   The `value` argument can be a key-value coding compliant object, an array or dictionary returned from the methods in
   `NSJSONSerialization`, or an array containing one element for each managed property.
  
   An exception will be thrown if any required properties are not present and those properties
   were not defined with default values.
  
   If the `value` argument is an array, all properties must be present, valid and in the same
   order as the properties defined in the model.
  
   @param realm    The Realm which should manage the newly-created object.
   @param value    The value used to populate the object.
  
   @see   `defaultPropertyValues`
   */
  + (instancetype)createInRealm:(RLMRealm *)realm withValue:(id)value;
  
  /**
   Creates or updates a Realm object within the default Realm.
  
   This method may only be called on Realm object types with a primary key defined. If there is already
   an object with the same primary key value in the default Realm, its values are updated and the object
   is returned. Otherwise, this method creates and populates a new instance of the object in the default Realm.
  
   If nested objects are included in the argument, `createOrUpdateInDefaultRealmWithValue:` will be
   recursively called on them if they have primary keys, `createInDefaultRealmWithValue:` if they do not.
  
   The `value` argument is used to populate the object. It can be a Realm object, a key-value coding
   compliant object, an array or dictionary returned from the methods in `NSJSONSerialization`, or an
   array containing one element for each managed property.
  
   If the object is being created, an exception will be thrown if any required properties
   are not present and those properties were not defined with default values.
  
   If the `value` argument is a Realm object already managed by the default Realm, the
   argument's type is the same as the receiver, and the objects have identical values for
   their managed properties, this method does nothing.
  
   If the object is being updated, each property defined in its schema will be set by copying from
   `value` using key-value coding. If the `value` argument does not respond to `valueForKey:` for a
   given property name (or getter name, if defined), that value will remain untouched.
   Nullable properties on the object can be set to nil by using `NSNull` as the updated value.
   Each property is set even if the existing value is the same as the new value being set, and
   notifications will report them all being changed. See `createOrUpdateModifiedInDefaultRealmWithValue:`
   for a version of this function which only sets the values which have changed.
  
   If the `value` argument is an array, all properties must be present, valid and in the same
   order as the properties defined in the model.
  
   @param value    The value used to populate the object.
  
   @see   `defaultPropertyValues`, `primaryKey`
   */
  + (instancetype)createOrUpdateInDefaultRealmWithValue:(id)value;
  
  /**
   Creates or updates a Realm object within the default Realm.
  
   This method may only be called on Realm object types with a primary key defined. If there is already
   an object with the same primary key value in the default Realm, its values are updated and the object
   is returned. Otherwise, this method creates and populates a new instance of the object in the default Realm.
  
   If nested objects are included in the argument, `createOrUpdateModifiedInDefaultRealmWithValue:` will be
   recursively called on them if they have primary keys, `createInDefaultRealmWithValue:` if they do not.
  
   The `value` argument is used to populate the object. It can be a Realm object, a key-value coding
   compliant object, an array or dictionary returned from the methods in `NSJSONSerialization`, or an
   array containing one element for each managed property.
  
   If the object is being created, an exception will be thrown if any required properties
   are not present and those properties were not defined with default values.
  
   If the `value` argument is a Realm object already managed by the default Realm, the
   argument's type is the same as the receiver, and the objects have identical values for
   their managed properties, this method does nothing.
  
   If the object is being updated, each property defined in its schema will be set by copying from
   `value` using key-value coding. If the `value` argument does not respond to `valueForKey:` for a
   given property name (or getter name, if defined), that value will remain untouched.
   Nullable properties on the object can be set to nil by using `NSNull` as the updated value.
   Unlike `createOrUpdateInDefaultRealmWithValue:`, only properties which have changed in value are
   set, and any change notifications produced by this call will report only which properies have
   actually changed.
  
   Checking which properties have changed imposes a small amount of overhead, and so this method
   may be slower when all or nearly all of the properties being set have changed. If most or all
   of the properties being set have not changed, this method will be much faster than unconditionally
   setting all of them, and will also reduce how much data has to be written to the Realm, saving
   both i/o time and disk space.
  
   If the `value` argument is an array, all properties must be present, valid and in the same
   order as the properties defined in the model.
  
   @param value    The value used to populate the object.
  
   @see   `defaultPropertyValues`, `primaryKey`
   */
  + (instancetype)createOrUpdateModifiedInDefaultRealmWithValue:(id)value;
  
  /**
   Creates or updates an Realm object within a specified Realm.
  
   This method may only be called on Realm object types with a primary key defined. If there is already
   an object with the same primary key value in the given Realm, its values are updated and the object
   is returned. Otherwise this method creates and populates a new instance of this object in the given Realm.
  
   If nested objects are included in the argument, `createOrUpdateInRealm:withValue:` will be
   recursively called on them if they have primary keys, `createInRealm:withValue:` if they do not.
  
   The `value` argument is used to populate the object. It can be a Realm object, a key-value coding
   compliant object, an array or dictionary returned from the methods in `NSJSONSerialization`, or an
   array containing one element for each managed property.
  
   If the object is being created, an exception will be thrown if any required properties
   are not present and those properties were not defined with default values.
  
   If the `value` argument is a Realm object already managed by the given Realm, the
   argument's type is the same as the receiver, and the objects have identical values for
   their managed properties, this method does nothing.
  
   If the object is being updated, each property defined in its schema will be set by copying from
   `value` using key-value coding. If the `value` argument does not respond to `valueForKey:` for a
   given property name (or getter name, if defined), that value will remain untouched.
   Nullable properties on the object can be set to nil by using `NSNull` as the updated value.
   Each property is set even if the existing value is the same as the new value being set, and
   notifications will report them all being changed. See `createOrUpdateModifiedInRealm:withValue:`
   for a version of this function which only sets the values which have changed.
  
   If the `value` argument is an array, all properties must be present, valid and in the same
   order as the properties defined in the model.
  
   @param realm    The Realm which should own the object.
   @param value    The value used to populate the object.
  
   @see   `defaultPropertyValues`, `primaryKey`
   */
  + (instancetype)createOrUpdateInRealm:(RLMRealm *)realm withValue:(id)value;
  
  /**
   Creates or updates an Realm object within a specified Realm.
  
   This method may only be called on Realm object types with a primary key defined. If there is already
   an object with the same primary key value in the given Realm, its values are updated and the object
   is returned. Otherwise this method creates and populates a new instance of this object in the given Realm.
  
   If nested objects are included in the argument, `createOrUpdateInRealm:withValue:` will be
   recursively called on them if they have primary keys, `createInRealm:withValue:` if they do not.
  
   The `value` argument is used to populate the object. It can be a Realm object, a key-value coding
   compliant object, an array or dictionary returned from the methods in `NSJSONSerialization`, or an
   array containing one element for each managed property.
  
   If the object is being created, an exception will be thrown if any required properties
   are not present and those properties were not defined with default values.
  
   If the `value` argument is a Realm object already managed by the given Realm, the
   argument's type is the same as the receiver, and the objects have identical values for
   their managed properties, this method does nothing.
  
   If the object is being updated, each property defined in its schema will be set by copying from
   `value` using key-value coding. If the `value` argument does not respond to `valueForKey:` for a
   given property name (or getter name, if defined), that value will remain untouched.
   Nullable properties on the object can be set to nil by using `NSNull` as the updated value.
   Unlike `createOrUpdateInRealm:withValue:`, only properties which have changed in value are
   set, and any change notifications produced by this call will report only which properies have
   actually changed.
  
   Checking which properties have changed imposes a small amount of overhead, and so this method
   may be slower when all or nearly all of the properties being set have changed. If most or all
   of the properties being set have not changed, this method will be much faster than unconditionally
   setting all of them, and will also reduce how much data has to be written to the Realm, saving
   both i/o time and disk space.
  
   If the `value` argument is an array, all properties must be present, valid and in the same
   order as the properties defined in the model.
  
   @param realm    The Realm which should own the object.
   @param value    The value used to populate the object.
  
   @see   `defaultPropertyValues`, `primaryKey`
   */
  + (instancetype)createOrUpdateModifiedInRealm:(RLMRealm *)realm withValue:(id)value;
  
  #pragma mark - Properties
  
  /**
   The Realm which manages the object, or `nil` if the object is unmanaged.
   */
  @property (nonatomic, readonly, nullable) RLMRealm *realm;
  
  /**
   The object schema which lists the managed properties for the object.
   */
  @property (nonatomic, readonly) RLMObjectSchema *objectSchema;
  
  /**
   Indicates if the object can no longer be accessed because it is now invalid.
  
   An object can no longer be accessed if the object has been deleted from the Realm that manages it, or
   if `invalidate` is called on that Realm.
   */
  @property (nonatomic, readonly, getter = isInvalidated) BOOL invalidated;
  
  /**
   Indicates if this object is frozen.
  
   @see `-[RLMObject freeze]`
   */
  @property (nonatomic, readonly, getter = isFrozen) BOOL frozen;
  
  
  #pragma mark - Customizing your Objects
  
  /**
   Returns an array of property names for properties which should be indexed.
  
   Only string, integer, boolean, and `NSDate` properties are supported.
  
   @return    An array of property names.
   */
  + (NSArray<NSString *> *)indexedProperties;
  
  /**
   Override this method to specify the default values to be used for each property.
  
   @return    A dictionary mapping property names to their default values.
   */
  + (nullable NSDictionary *)defaultPropertyValues;
  
  /**
   Override this method to specify the name of a property to be used as the primary key.
  
   Only properties of types `RLMPropertyTypeString` and `RLMPropertyTypeInt` can be designated as the primary key.
   Primary key properties enforce uniqueness for each value whenever the property is set, which incurs minor overhead.
   Indexes are created automatically for primary key properties.
  
   @return    The name of the property designated as the primary key.
   */
  + (nullable NSString *)primaryKey;
  
  /**
   Override this method to specify the names of properties to ignore. These properties will not be managed by the Realm
   that manages the object.
  
   @return    An array of property names to ignore.
   */
  + (nullable NSArray<NSString *> *)ignoredProperties;
  
  /**
   Override this method to specify the names of properties that are non-optional (i.e. cannot be assigned a `nil` value).
  
   By default, all properties of a type whose values can be set to `nil` are considered optional properties.
   To require that an object in a Realm always store a non-`nil` value for a property,
   add the name of the property to the array returned from this method.
  
   Properties of `RLMObject` type cannot be non-optional. Array and `NSNumber` properties
   can be non-optional, but there is no reason to do so: arrays do not support storing nil, and
   if you want a non-optional number you should instead use the primitive type.
  
   @return    An array of property names that are required.
   */
  + (NSArray<NSString *> *)requiredProperties;
  
  /**
   Override this method to provide information related to properties containing linking objects.
  
   Each property of type `RLMLinkingObjects` must have a key in the dictionary returned by this method consisting
   of the property name. The corresponding value must be an instance of `RLMPropertyDescriptor` that describes the class
   and property that the property is linked to.
  
       return @{ @"owners": [RLMPropertyDescriptor descriptorWithClass:Owner.class propertyName:@"dogs"] };
  
   @return     A dictionary mapping property names to `RLMPropertyDescriptor` instances.
   */
  + (NSDictionary<NSString *, RLMPropertyDescriptor *> *)linkingObjectsProperties;
  
  
  #pragma mark - Getting & Querying Objects from the Default Realm
  
  /**
   Returns all objects of this object type from the default Realm.
  
   @return    An `RLMResults` containing all objects of this type in the default Realm.
   */
  + (RLMResults *)allObjects;
  
  /**
   Returns all objects of this object type matching the given predicate from the default Realm.
  
   @param predicateFormat A predicate format string, optionally followed by a variable number of arguments.
  
   @return    An `RLMResults` containing all objects of this type in the default Realm that match the given predicate.
   */
  + (RLMResults *)objectsWhere:(NSString *)predicateFormat, ...;
  
  /// :nodoc:
  + (RLMResults<__kindof RLMObject *> *)objectsWhere:(NSString *)predicateFormat args:(va_list)args;
  
  
  /**
   Returns all objects of this object type matching the given predicate from the default Realm.
  
   @param predicate   The predicate with which to filter the objects.
  
   @return    An `RLMResults` containing all objects of this type in the default Realm that match the given predicate.
   */
  + (RLMResults *)objectsWithPredicate:(nullable NSPredicate *)predicate;
  
  /**
   Retrieves the single instance of this object type with the given primary key from the default Realm.
  
   Returns the object from the default Realm which has the given primary key, or
   `nil` if the object does not exist. This is slightly faster than the otherwise
   equivalent `[[SubclassName objectsWhere:@"primaryKeyPropertyName = %@", key] firstObject]`.
  
   This method requires that `primaryKey` be overridden on the receiving subclass.
  
   @return    An object of this object type, or `nil` if an object with the given primary key does not exist.
   @see       `-primaryKey`
   */
  + (nullable instancetype)objectForPrimaryKey:(nullable id)primaryKey NS_SWIFT_NAME(object(forPrimaryKey:));
  
  
  #pragma mark - Querying Specific Realms
  
  /**
   Returns all objects of this object type from the specified Realm.
  
   @param realm   The Realm to query.
  
   @return        An `RLMResults` containing all objects of this type in the specified Realm.
   */
  + (RLMResults *)allObjectsInRealm:(RLMRealm *)realm;
  
  /**
   Returns all objects of this object type matching the given predicate from the specified Realm.
  
   @param predicateFormat A predicate format string, optionally followed by a variable number of arguments.
   @param realm           The Realm to query.
  
   @return    An `RLMResults` containing all objects of this type in the specified Realm that match the given predicate.
   */
  + (RLMResults *)objectsInRealm:(RLMRealm *)realm where:(NSString *)predicateFormat, ...;
  
  /// :nodoc:
  + (RLMResults<__kindof RLMObject *> *)objectsInRealm:(RLMRealm *)realm where:(NSString *)predicateFormat args:(va_list)args;
  
  /**
   Returns all objects of this object type matching the given predicate from the specified Realm.
  
   @param predicate   A predicate to use to filter the elements.
   @param realm       The Realm to query.
  
   @return    An `RLMResults` containing all objects of this type in the specified Realm that match the given predicate.
   */
  + (RLMResults *)objectsInRealm:(RLMRealm *)realm withPredicate:(nullable NSPredicate *)predicate;
  
  /**
   Retrieves the single instance of this object type with the given primary key from the specified Realm.
  
   Returns the object from the specified Realm which has the given primary key, or
   `nil` if the object does not exist. This is slightly faster than the otherwise
   equivalent `[[SubclassName objectsInRealm:realm where:@"primaryKeyPropertyName = %@", key] firstObject]`.
  
   This method requires that `primaryKey` be overridden on the receiving subclass.
  
   @return    An object of this object type, or `nil` if an object with the given primary key does not exist.
   @see       `-primaryKey`
   */
  + (nullable instancetype)objectInRealm:(RLMRealm *)realm forPrimaryKey:(nullable id)primaryKey NS_SWIFT_NAME(object(in:forPrimaryKey:));
  
  #pragma mark - Notifications
  
  /**
   A callback block for `RLMObject` notifications.
  
   If the object is deleted from the managing Realm, the block is called with
   `deleted` set to `YES` and the other two arguments are `nil`. The block will
   never be called again after this.
  
   If the object is modified, the block will be called with `deleted` set to
   `NO`, a `nil` error, and an array of `RLMPropertyChange` objects which
   indicate which properties of the objects were modified.
  
   If an error occurs, `deleted` will be `NO`, `changes` will be `nil`, and
   `error` will include information about the error. The block will never be
   called again after an error occurs.
   */
  typedef void (^RLMObjectChangeBlock)(BOOL deleted,
                                       NSArray<RLMPropertyChange *> *_Nullable changes,
                                       NSError *_Nullable error);
  
  /**
   Registers a block to be called each time the object changes.
  
   The block will be asynchronously called after each write transaction which
   deletes the object or modifies any of the managed properties of the object,
   including self-assignments that set a property to its existing value.
  
   For write transactions performed on different threads or in different
   processes, the block will be called when the managing Realm is
   (auto)refreshed to a version including the changes, while for local write
   transactions it will be called at some point in the future after the write
   transaction is committed.
  
   Notifications are delivered via the standard run loop, and so can't be
   delivered while the run loop is blocked by other activity. When notifications
   can't be delivered instantly, multiple notifications may be coalesced into a
   single notification.
  
   Unlike with `RLMArray` and `RLMResults`, there is no "initial" callback made
   after you add a new notification block.
  
   Only objects which are managed by a Realm can be observed in this way. You
   must retain the returned token for as long as you want updates to be sent to
   the block. To stop receiving updates, call `-invalidate` on the token.
  
   It is safe to capture a strong reference to the observed object within the
   callback block. There is no retain cycle due to that the callback is retained
   by the returned token and not by the object itself.
  
   @warning This method cannot be called during a write transaction, when the
            containing Realm is read-only, or on an unmanaged object.
  
   @param block The block to be called whenever a change occurs.
   @return A token which must be held for as long as you want updates to be delivered.
   */
  - (RLMNotificationToken *)addNotificationBlock:(RLMObjectChangeBlock)block;
  
  /**
   Registers a block to be called each time the object changes.
  
   The block will be asynchronously called after each write transaction which
   deletes the object or modifies any of the managed properties of the object,
   including self-assignments that set a property to its existing value.
  
   For write transactions performed on different threads or in different
   processes, the block will be called when the managing Realm is
   (auto)refreshed to a version including the changes, while for local write
   transactions it will be called at some point in the future after the write
   transaction is committed.
  
   Notifications are delivered on the given queue. If the queue is blocked and
   notifications can't be delivered instantly, multiple notifications may be
   coalesced into a single notification.
  
   Unlike with `RLMArray` and `RLMResults`, there is no "initial" callback made
   after you add a new notification block.
  
   Only objects which are managed by a Realm can be observed in this way. You
   must retain the returned token for as long as you want updates to be sent to
   the block. To stop receiving updates, call `-invalidate` on the token.
  
   It is safe to capture a strong reference to the observed object within the
   callback block. There is no retain cycle due to that the callback is retained
   by the returned token and not by the object itself.
  
   @warning This method cannot be called during a write transaction, when the
            containing Realm is read-only, or on an unmanaged object.
   @warning The queue must be a serial queue.
  
   @param block The block to be called whenever a change occurs.
   @param queue The serial queue to deliver notifications to.
   @return A token which must be held for as long as you want updates to be delivered.
   */
  - (RLMNotificationToken *)addNotificationBlock:(RLMObjectChangeBlock)block queue:(dispatch_queue_t)queue;
  
  /**
   Registers a block to be called each time the object changes.
  
   The block will be asynchronously called after each write transaction which
   deletes the object or modifies any of the managed properties of the object,
   including self-assignments that set a property to its existing value.
  
   For write transactions performed on different threads or in different
   processes, the block will be called when the managing Realm is
   (auto)refreshed to a version including the changes, while for local write
   transactions it will be called at some point in the future after the write
   transaction is committed.
  
   Notifications are delivered on the given queue. If the queue is blocked and
   notifications can't be delivered instantly, multiple notifications may be
   coalesced into a single notification.
  
   Unlike with `RLMArray` and `RLMResults`, there is no "initial" callback made
   after you add a new notification block.
  
   Only objects which are managed by a Realm can be observed in this way. You
   must retain the returned token for as long as you want updates to be sent to
   the block. To stop receiving updates, call `-invalidate` on the token.
  
   It is safe to capture a strong reference to the observed object within the
   callback block. There is no retain cycle due to that the callback is retained
   by the returned token and not by the object itself.
  
   @warning This method cannot be called during a write transaction, when the
            containing Realm is read-only, or on an unmanaged object.
   @warning The queue must be a serial queue.
  
   @param block The block to be called whenever a change occurs.
   @param keyPaths The block will be called for changes occuring on these keypaths. If no
   key paths are given, notifications are delivered for every property key path.
   @param queue The serial queue to deliver notifications to.
   @return A token which must be held for as long as you want updates to be delivered.
   */
  - (RLMNotificationToken *)addNotificationBlock:(RLMObjectChangeBlock)block keyPaths:(NSArray<NSString *> *)keyPaths queue:(dispatch_queue_t)queue;
  
  /**
   Registers a block to be called each time the object changes.
  
   The block will be asynchronously called after each write transaction which
   deletes the object or modifies any of the managed properties of the object,
   including self-assignments that set a property to its existing value.
  
   For write transactions performed on different threads or in different
   processes, the block will be called when the managing Realm is
   (auto)refreshed to a version including the changes, while for local write
   transactions it will be called at some point in the future after the write
   transaction is committed.
  
   Notifications are delivered on the given queue. If the queue is blocked and
   notifications can't be delivered instantly, multiple notifications may be
   coalesced into a single notification.
  
   Unlike with `RLMArray` and `RLMResults`, there is no "initial" callback made
   after you add a new notification block.
  
   Only objects which are managed by a Realm can be observed in this way. You
   must retain the returned token for as long as you want updates to be sent to
   the block. To stop receiving updates, call `-invalidate` on the token.
  
   It is safe to capture a strong reference to the observed object within the
   callback block. There is no retain cycle due to that the callback is retained
   by the returned token and not by the object itself.
  
   @warning This method cannot be called during a write transaction, when the
            containing Realm is read-only, or on an unmanaged object.
   @warning The queue must be a serial queue.
  
   @param block The block to be called whenever a change occurs.
   @param keyPaths The block will be called for changes occuring on these keypaths. If no
   key paths are given, notifications are delivered for every property key path.
   @return A token which must be held for as long as you want updates to be delivered.
   */
  - (RLMNotificationToken *)addNotificationBlock:(RLMObjectChangeBlock)block keyPaths:(NSArray<NSString *> *)keyPaths;
  
  
  #pragma mark - Other Instance Methods
  
  /**
   Returns YES if another Realm object instance points to the same object as the receiver in the Realm managing
   the receiver.
  
   For frozen objects and object types with a primary key, `isEqual:` is
   overridden to use the same logic as this method (along with a corresponding
   implementation for `hash`). Non-frozen objects without primary keys use
   pointer identity for `isEqual:` and `hash`.
  
   @param object  The object to compare the receiver to.
  
   @return    Whether the object represents the same object as the receiver.
   */
  - (BOOL)isEqualToObject:(RLMObject *)object;
  
  /**
   Returns a frozen (immutable) snapshot of this object.
  
   The frozen copy is an immutable object which contains the same data as this
   object currently contains, but will not update when writes are made to the
   containing Realm. Unlike live objects, frozen objects can be accessed from any
   thread.
  
   - warning: Holding onto a frozen object for an extended period while performing write
   transaction on the Realm may result in the Realm file growing to large sizes. See
   `Realm.Configuration.maximumNumberOfActiveVersions` for more information.
   - warning: This method can only be called on a managed object.
   */
  - (instancetype)freeze NS_RETURNS_RETAINED;
  
  /**
   Returns a live (mutable) reference of this object.
  
   This method creates a managed accessor to a live copy of the same frozen object.
   Will return self if called on an already live object.
   */
  - (instancetype)thaw;
  
  #pragma mark - Dynamic Accessors
  
  /// :nodoc:
  - (nullable id)objectForKeyedSubscript:(NSString *)key;
  
  /// :nodoc:
  - (void)setObject:(nullable id)obj forKeyedSubscript:(NSString *)key;
  
  @end
  
  /**
   Information about a specific property which changed in an `RLMObject` change notification.
   */
  @interface RLMPropertyChange : NSObject
  
  /**
   The name of the property which changed.
   */
  @property (nonatomic, readonly, strong) NSString *name;
  
  /**
   The value of the property before the change occurred. This will always be `nil`
   if the change happened on the same thread as the notification and for `RLMArray`
   properties.
  
   For object properties this will give the object which was previously linked to,
   but that object will have its new values and not the values it had before the
   changes. This means that `previousValue` may be a deleted object, and you will
   need to check `invalidated` before accessing any of its properties.
   */
  @property (nonatomic, readonly, strong, nullable) id previousValue;
  
  /**
   The value of the property after the change occurred. This will always be `nil`
   for `RLMArray` properties.
   */
  @property (nonatomic, readonly, strong, nullable) id value;
  @end
  
  #pragma mark - RLMArray Property Declaration
  
  /**
   Properties on `RLMObject`s of type `RLMArray` must have an associated type. A type is associated
   with an `RLMArray` property by defining a protocol for the object type that the array should contain.
   To define the protocol for an object, you can use the macro RLM_ARRAY_TYPE:
  
       RLM_ARRAY_TYPE(ObjectType)
       ...
       @property RLMArray<ObjectType *><ObjectType> *arrayOfObjectTypes;
    */
  #define RLM_ARRAY_TYPE(RLM_OBJECT_SUBCLASS)\
  __attribute__((deprecated("RLM_ARRAY_TYPE has been deprecated. Use RLM_COLLECTION_TYPE instead."))) \
  @protocol RLM_OBJECT_SUBCLASS <NSObject>  \
  @end
  
  /**
   Properties on `RLMObject`s of type `RLMSet`  /  `RLMArray` must have an associated type. A type is associated
   with an `RLMSet`  /  `RLMArray` property by defining a protocol for the object type that the array should contain.
   To define the protocol for an object, you can use the macro RLM_COLLECTION_TYPE:
  
       RLM_COLLECTION_TYPE(ObjectType)
       ...
       @property RLMSet<ObjectType *><ObjectType> *setOfObjectTypes;
       @property RLMArray<ObjectType *><ObjectType> *arrayOfObjectTypes;
    */
  #define RLM_COLLECTION_TYPE(RLM_OBJECT_SUBCLASS)\
  @protocol RLM_OBJECT_SUBCLASS <NSObject>   \
  @end
  
  NS_ASSUME_NONNULL_END