Reputation: 13256
When declaring an RLMArray, what is the significance of the second set of brackets? Realm is the only place I've seen this used.
@property NSArray<NSDictionary*> *dictionaries; // I understand this (and it's wonderful!)
@property NSDictionary<NSString*, NSArray<NSString*>*> *dictionaryOfArraysOfStrings; // No problem with this either
@property RLMArray<Object*><Object> *objects; // What is <Object> for?
Upvotes: 2
Views: 325
Reputation: 18308
The two sets of angle brackets are for Objective-C generics and protocols respectively. Objective-C generics lets the compiler know that methods like -[RLMArray firstObject]
return the specific type of object that the array contains, rather than any possible RLMObject
subclass. Sadly this extra type information is erased at runtime, so Realm has no way to tell from the use of Objective-C generics alone in the property declaration what type of object the array contains. This is where the protocol conformance comes in. The protocol that a property conforms to is available to Realm at runtime, and so is used to inform Realm of the object type that your RLMArray
property will contain. Realm provides the RLM_ARRAY_TYPE
macro to declare a protocol of the same name as a model class, so it is easy to miss that a protocol is involved.
Upvotes: 6