T.Akashi
T.Akashi

Reputation: 1221

Realm does not stored data in iOS

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!

Upvotes: 0

Views: 650

Answers (2)

jpsim
jpsim

Reputation: 14409

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.

Upvotes: 1

Zander Zhang
Zander Zhang

Reputation: 65

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

Upvotes: 0

Related Questions