I have a simple realm object like this:
@interface Person : RLMObject
@property NSString *name;
@end
RLM_ARRAY_TYPE(Person)
Now I like to test something with realm.io this way:
#import <XCTest/XCTest.h>
#import "Person.h"
@interface PersonTests : XCTestCase
@end
@implementation PersonTests
- (void)setUp {[super setUp];}
- (void)tearDown {[super tearDown];}
- (void)testFooBar
{
// !!! the test crashes right here!!!!
Person *person = [[Person alloc] init];
person.name = @"foobar";
RLMRealm *realm = [RLMRealm defaultRealm];
[realm beginWriteTransaction];
[realm addObject:person];
[realm commitWriteTransaction];
......
}
... but the test crashes in the first line (Person *person = [[Person alloc] init];) with the following error
*** Terminating app due to uncaught exception 'RLMException', reason: 'objectClass must derive from RLMObject'
Does anyone know what I am doing wrong? I'm thankful for any hint!!
I was having the same error, and after 4 hours of delete, clone, clean, re-install pods, repeat... what works for me is:
link_with 'MyProject', 'MyProjectTests'
#common pods such as CocoaLumberjack
pod 'Realm', '0.89.0'
target 'MyProjectTests', exclusive: true do
pod 'Realm/Headers'
end
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import <Realm/Realm.h>
#import "RealmObjectSubclass.h"
- (void)setUp {
[super setUp];
NSString *resourcePath = [NSBundle bundleForClass:[self.class]].resourcePath;
NSString *testRealPath = [NSString stringWithFormat:@"%@.test", resourcePath];
[RLMRealm setDefaultRealmPath:testRealPath];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With