Search code examples
iosobjective-crealm

RLMException', reason: 'Property 'productos' requires a protocol defining the contained type - example: RLMArray


So I am using a Realm for my project, I have an object, 'Pedido' (spanish for order) that has many 'V3Producto' objects, as follows:

@interface V3Producto : RLMObject

@property NSString                  *codeProd; // Este es el código de barras!
@property NSString                  *codigo;
@property NSNumber<RLMDouble>       *descuento;
@property NSString                  *detailProd;
@property NSInteger     idid;
@property NSInteger     idCompania;
@property NSNumber<RLMDouble> *priceProd;
@property NSInteger     stock;

@property int      cantidadComprada;
@property int      cantidad; // cantidad de stock

And the code for the 'Pedidos' (orders)

@interface Pedido : RLMObject

@property NSNumber<RLMDouble>   *idUbicacion;
@property NSString              *fechaPedido;
@property NSString              *sucursal;
@property NSNumber<RLMDouble>   *filterId;
@property RLMArray<V3Producto*>       *productos;

When I run the app, as soon as it loads I get the error: 'RLMException', reason: 'Property 'productos' requires a protocol defining the contained type - example: RLMArray' which is quite strange since, before adding the RLMArray seemed to work just fine! Any V3Producto seems to be a perfectly fine and valid RLMObject! Any ideas?

EDIT: I've tried renaming 'productos' to something else as other threads with the same name suggest but that didn't fix it.


Solution

  • The proper way to declare a RLMArray, would be as follows:

    RLM_ARRAY_TYPE(V3Producto)
    
    @interface Pedido : RLMObject
    
    @property NSNumber<RLMDouble>   *idUbicacion;
    ...    
    @property RLMArray<V3Producto*><V3Producto>       *productosPedido;
    

    Note the I had to declare the type I want to use as an array with a MACRO (in the first line) and the declaration of the array is slightly different (you have to set the type plus the macro you've declared).