我将获取结果(NSArray)分配给另一个数组,因此我可以轻松地在表视图中显示但是所有NSManagedObject属性都是nil ...我如何强制访问持久数据库?
这是我的代码:
使事情更简单的类别:
+ (NSString *)CDentityName {
return NSStringFromClass(self);
}
+ (instancetype)CDInsertNewObjectIntoContext:(NSManagedObjectContext *)context {
return [NSEntityDescription insertNewObjectForEntityForName:[self CDentityName] inManagedObjectContext:context];
}
分配:
AppDelegate * delegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
NSManagedObjectContext *contex = delegate.persistentContainer.viewContext;
HILNetwork * network = [HILNetwork CDInsertNewObjectIntoContext:contex];
network.name = fullDomain;
[delegate saveContext];
撷取:
[_user network:^(NSURLSessionDataTask * _Nonnull task, NSArray * _Nullable networks) {
NSLog(@"Got %lu networks", networks.count);
[myNetworks removeAllObjects];
[myNetworks addObjectsFromArray:networks];
[tableView reloadData];
//[appDelegate saveContext];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"FETCH FAILED! %@", error.localizedDescription);
} progress:^(NSProgress * _Nonnull downloadProgress) {}];
然后在cellForRowAtIndexPath
我总是得到:
<HILNetwork: 0x6100000fa100> (entity: HILNetwork; id: 0xd000000000540004 <x-coredata://EEDB35CD-8FF3-4E6D-A207-4B57ECC8DC53/HILNetwork/p21> ; data: <fault>)
所以网络名称是:( null)
我该如何解决? 这让我发疯了!
由于