0

I'm trying to store data with Realm in iOS but I'm facing the problem it does not stored data. I found similar question but I'm not sure how to get existing database.

Why is my Realm object not saving stored values?

Here is my code.

@interface database : RLMObject
@property NSString *name;
@property NSString *age;
@end

@implementation database
@end

RLM_ARRAY_TYPE(database)

In Appdelegate.m

database *db = [[database alloc] init];
db.name    = @"David Test";
db.age = @"30";

[realm beginWriteTransaction];
[realm addObject:db];
[realm commitWriteTransaction];

Then I get allObjects like below

RLMResults *result = [database allObjects];

Shutting down app once,RLMResults has no data.

Does anyone have any idea?

Thanks in advance!

Community
  • 1
  • 1
T.Akashi
  • 1,201
  • 1
  • 13
  • 17

2 Answers2

1

Is it possible the realm variable you're using is initialized with +[RLMRealm realmWithPath:]? The [database allObjects] call will only query the default realm (created with [RLMRealm defaultRealm]).

Although it's impossible to say with any certainty what exactly is happening without more information.

jpsim
  • 14,329
  • 6
  • 51
  • 68
  • Sorry, yes I'm using `[RLMRealm defaultRealm]` . I'm not using no more realm code. Just installed with cocoapods `pod Realm` and created "database" class file. – T.Akashi Apr 29 '15 at 23:34
  • Hi Akashi, I've created a small sample project with the code you've posted and Realm installed via CocoaPods. Everything works fine in there. Could you please try it and let me know A) if it works for you and B) if your project does anything differently that might lead to different behavior. https://static.realm.io/debug/Akashi.tgz – jpsim Apr 30 '15 at 21:54
0

I use FMDB, you could search it through here.https://github.com/realm/realm-cocoa ,github. good luck

  • Links may be deleted or changed in the future. Please post the relevant portions of the link here so that this answer will always provide information to future readers. – Thom Apr 29 '15 at 11:35