1

有没有办法以编程方式获取核心数据对象的大小(以字节为单位)?

4

2 回答 2

1

在这里,存在将NSManagedObjectID 转换为 NSData的 SO 线程

NSURL * url = [[YOUROBJECT objectID] URIRepresentation];
NSData * urlData = [NSKeyedArchiver archivedDataWithRootObject:url];
NSLog(@"Data Length :%d",[urlData length]);
于 2013-04-10T11:41:47.477 回答
0

您可以使用下面的代码来计算单个 NSManagedObject 的数组和总和

- (void) calculateSize {

     NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Event"];

     NSArray *data = [self.managedObjectContext executeFetchRequest:request error:nil];

     NSLog(@"Size of %@: %zd", NSStringFromClass([data class]), malloc_size((__bridge const void *) data));


     int totalSize = 0;
     for(NSManagedObject *object in data)
     {
        totalSize += malloc_size((__bridge const void *) object);
     }
     NSLog(@"Managed Object Size total:%d", totalSize);
}
于 2016-05-18T12:42:11.550 回答