Reputation: 198
I have old project written on Objective-C. Need to do migration to Realm.
I created several objects/classes inheritance from RLMObject
. When I do fetching objects only with one main object type (ConnectionRealm
) - working fine, but if I do add (only add, not include, not use) to project two or more another classes (inheritance from RLMObject
), like as FloorRealm
class, APP crash on [ConnectionRealm allObjects]
without any errors.
Also ConnectionRealm
contains RLMArray
of FloorRealm
. App still crashing.
(Can`t solve and understand this few days.) Thanks.
Connection Model:
#import <Foundation/Foundation.h>
#import <Realm/Realm.h>
#import "FloorRealm.h"
@interface ConnectionRealm : RLMObject
@property int connectionID;
@property NSString *name;
@property NSString *localIPAddress;
@property NSString *localPort;
@property NSString *remoteIPAddress;
@property NSString *remotePort;
@property NSString *userName;
@property NSString *password;
@property NSString *deviceID;
@property RLMArray <FloorRealm *> *floors;
- (instancetype)initWith:(NSString *)name
localIP:(NSString *)localIPAddress
localPort:(NSString *)lPort
remoteIP:(NSString *)remoteIPAddress
remotePort:(NSString *)rPort
userName:(NSString *)userName
password:(NSString *)password
deviceID:(NSString *)deviceID;
@end
#import "ConnectionRealm.h"
@implementation ConnectionRealm
- (instancetype)initWith:(NSString *)name
localIP:(NSString *)localIPAddress
localPort:(NSString *)lPort
remoteIP:(NSString *)remoteIPAddress
remotePort:(NSString *)rPort
userName:(NSString *)userName
password:(NSString *)password
deviceID:(NSString *)deviceID {
if (self = [super init]) {
self.connectionID = [self incrementID];
self.name = name;
self.localIPAddress = localIPAddress;
self.localPort = lPort;
self.remoteIPAddress = remoteIPAddress;
self.remotePort = rPort;
self.userName = userName;
self.password = password;
self.deviceID = deviceID;
}
return self;
}
+ (NSString *)primaryKey { return @"connectionID"; }
- (int)incrementID {
RLMResults *objects = [ConnectionRealm allObjects];
return self.connectionID = [[objects maxOfProperty:@"connectionID"] intValue] + 1;
}
@end
FloorModel:
#import <Realm/Realm.h>
@interface FloorRealm : RLMObject
@property int floorID;
@property NSInteger floorNumber;
@property NSString *floorName;
- (instancetype)initWith:(NSInteger)floorNumber floorName:(NSString *)name;
@end
RLM_ARRAY_TYPE(FloorRealm)
#import "FloorRealm.h"
@implementation FloorRealm
- (instancetype)initWith:(NSInteger)floorNumber floorName:(NSString *)name {
if (self = [super init]) {
self.floorID = [self incrementID];
self.floorNumber = floorNumber;
self.floorName = name;
}
return self;
}
+ (NSString *)primaryKey { return @"floorID"; }
- (int)incrementID {
RLMResults *objects = [FloorRealm allObjects];
return self.floorID = [[objects maxOfProperty:@"floorID"] intValue] + 1;
}
@end
Upvotes: 0
Views: 346
Reputation: 198
[SOLVED]
RLM_ARRAY_TYPE(FloorRealm)
need put on ConnectionRealm in .h after #includes. But in official docs written another.RLMArray <FloorRealm *><FloorRealm> *floors;
instead of @property RLMArray <FloorRealm *> *floors;
I created test project with the same models and seed all errors. Strange, but in original project Xcode not showing this errors.
Upvotes: 1