在RLMObject的子类中声明了一个Bool属性,如下所示:
@interface PhotoRealm : RLMObject
@property NSNumber<RLMBool> *isVoted;
- (id)initWithMantleModel:(PhotoModel *)photoModel;
@end
在.m文件中,我已将-defaultPropertyValues
实现为init,如下所示:
+ (NSDictionary *)defaultPropertyValues {
return @{@"isVoted" : @NO};
}
在某个地方,我需要通过丛林做一些bool值,但结果不是预期的。 然后,我编写以下调试代码:
if (photoRealm.isVoted) {
NSLog(@"isVoted");
} else {
NSLog(@"unVoted");
}
NSLog(@"%ld", (NSInteger)photoRealm.isVoted);
记录如下:
[15:32:43] - [DTCollectionViewCell setupContentWithPhotoModel:] [306行] isVoted [15:32:43] - [DTCollectionViewCell setupContentWithPhotoModel:] [311行] 4646266992
同时,realm文件的快照如下:
我被困在这里。
答案 0 :(得分:1)
我想我已经解决了。
实际上,isVoted
是 NSNumber ,所以代码应该是这样的:
if ([photo.isVoted integerValue]) {
NSLog(@"isVoted");
} else {
NSLog(@"unVoted");
}
NSLog(@"%ld", [photo.isVoted integerValue]);
答案 1 :(得分:0)
您需要将其用作。
Nov 8 08:35:04 rockpro64 gunicorn[24608]: creation of dataframe for object_ai
Nov 8 08:35:04 rockpro64 gunicorn[24608]: 2019-11-08 08:35:04,050 INFO sqlalchemy.engine.base.Engine select timestamp, value from db.tldata where pointId = (select Id from db.device_pointList where DeviceId = ( select Id from db.device where device_instance =200) and ObjectId = 7 and object='trendLog') and timestamp between '2019-10-30 00:00:00' and '2019-10-31 23:59:59'
Nov 8 08:35:04 rockpro64 gunicorn[24608]: 2019-11-08 08:35:04,050 INFO sqlalchemy.engine.base.Engine {}
Nov 8 08:35:04 rockpro64 gunicorn[24608]: value
Nov 8 08:35:04 rockpro64 gunicorn[24608]: timestamp
Nov 8 08:35:04 rockpro64 gunicorn[24608]: 2019-10-30 00:00:00 10.475613
Nov 8 08:35:04 rockpro64 gunicorn[24608]: 2019-10-30 00:15:00 8.461939
Nov 8 08:35:04 rockpro64 gunicorn[24608]: 2019-10-30 00:30:00 5.507755
Nov 8 08:35:04 rockpro64 gunicorn[24608]: 2019-10-30 00:45:00 8.461939
Nov 8 08:35:04 rockpro64 gunicorn[24608]: 2019-10-30 01:00:00 5.507755
Nov 8 08:35:04 rockpro64 gunicorn[24608]: ... ...
Nov 8 08:35:04 rockpro64 gunicorn[24608]: 2019-10-31 22:45:00 10.641429
Nov 8 08:35:04 rockpro64 gunicorn[24608]: 2019-10-31 23:00:00 1.556020
Nov 8 08:35:04 rockpro64 gunicorn[24608]: 2019-10-31 23:15:00 11.016837
Nov 8 08:35:04 rockpro64 gunicorn[24608]: 2019-10-31 23:30:00 8.576020
Nov 8 08:35:04 rockpro64 gunicorn[24608]: 2019-10-31 23:45:00 9.379898
Nov 8 08:35:04 rockpro64 gunicorn[24608]: [192 rows x 1 columns]
Nov 8 08:35:04 rockpro64 gunicorn[24608]: creation of dataframe for object_sp
Nov 8 08:35:04 rockpro64 gunicorn[24608]: 2019-11-08 08:35:04,187 INFO sqlalchemy.engine.base.Engine select timestamp, value from db.tldata where pointId = (select Id from db.device_pointList where DeviceId = ( select Id from db.device where device_instance =200) and ObjectId = 9 and object='trendLog') and timestamp between '2019-10-30 00:00:00' and '2019-10-31 23:59:59'
Nov 8 08:35:04 rockpro64 gunicorn[24608]: 2019-11-08 08:35:04,187 INFO sqlalchemy.engine.base.Engine {}