DBaccess IOS 框架。 NSString 字段中为 Nil
DBaccess IOS framework. Nil in NSString fields
我在尝试保存对象时遇到问题。保存后其属性为空。
我的对象:
@interface Route : DBObject
@property (strong) NSString* content;
@property bool hidden;
@end
测试代码:
[DBAccess setDelegate:self];
[DBAccess openDatabaseNamed:@"test"];
Route * route = [Route new];
route.content = @"test content";
route.hidden = true;
[route commit];
DBResultSet * routes = [[Route query] fetch];
for (Route * r in routes) {
NSLog(@"Route content %@, hidden %d", r.content, r.hidden);
}
po route
提交后给出:
| content | UNKNOWN | Nil value
| Id | NUMBER | 1.000000
| hidden | NUMBER | 0.000000
日志输出:
Route content (null), hidden 0
DBAccess 需要使用 @dynamic 实现的要使用 ORM 保留的属性。
DBAccess 将它自己的 getter 和 setter 注入 class,但是如果您使用 @synthesize,那么 Objective-c 传统上会为您创建这些,或者最近如果您没有指定它会自动创建任何东西。
下面是现在几乎完成的新网站的一部分,其中包含更清晰的帮助和说明:
4.) CREATE YOUR DATA OBJECTS
DBAccess objects are normal classes with properties defined on
them, the ORM then inspects all these classes and mirrors their
structure in a SQLite database. If you add or remove columns then the
tables are updated to represent the current structure of the classes.
Properties need to be implemented using @dynamic, this is to indicate
to the ORM that it will control the fetching and setting of these
values from the database.
Any properties that are implemented using @synthesize will not be
persisted, but DBAccess will not interfere with them either. This way
you can create large classes that are only partially utilised by the
ORM, but can remove the need for additional separate classes within
your application.
我在尝试保存对象时遇到问题。保存后其属性为空。
我的对象:
@interface Route : DBObject
@property (strong) NSString* content;
@property bool hidden;
@end
测试代码:
[DBAccess setDelegate:self];
[DBAccess openDatabaseNamed:@"test"];
Route * route = [Route new];
route.content = @"test content";
route.hidden = true;
[route commit];
DBResultSet * routes = [[Route query] fetch];
for (Route * r in routes) {
NSLog(@"Route content %@, hidden %d", r.content, r.hidden);
}
po route
提交后给出:
| content | UNKNOWN | Nil value
| Id | NUMBER | 1.000000
| hidden | NUMBER | 0.000000
日志输出:
Route content (null), hidden 0
DBAccess 需要使用 @dynamic 实现的要使用 ORM 保留的属性。
DBAccess 将它自己的 getter 和 setter 注入 class,但是如果您使用 @synthesize,那么 Objective-c 传统上会为您创建这些,或者最近如果您没有指定它会自动创建任何东西。
下面是现在几乎完成的新网站的一部分,其中包含更清晰的帮助和说明:
4.) CREATE YOUR DATA OBJECTS
DBAccess objects are normal classes with properties defined on them, the ORM then inspects all these classes and mirrors their structure in a SQLite database. If you add or remove columns then the tables are updated to represent the current structure of the classes.
Properties need to be implemented using @dynamic, this is to indicate to the ORM that it will control the fetching and setting of these values from the database.
Any properties that are implemented using @synthesize will not be persisted, but DBAccess will not interfere with them either. This way you can create large classes that are only partially utilised by the ORM, but can remove the need for additional separate classes within your application.