I make use of NSFetchedResultsController to display a bunch of objects, which are sectioned using dates. On a fresh install, it all works perfectly and the objects are displayed in the table view. However, it seems that when the app is relaunched I get a crash. I specify a cache when initialising the NSFetchedResultsController, and when I don't it works perfectly.
我使用NSFetchedResultsController来显示一组对象,这些对象使用日期分割。在一个新的安装中,所有的操作都是完美的,对象都显示在表视图中。然而,当程序重新启动时,我似乎会崩溃。在初始化NSFetchedResultsController时,我指定了一个缓存,如果没有,它就可以完美地工作。
Here is how I create my NSFetchedResultsController:
下面是我如何创建NSFetchedResultsController:
- (NSFetchedResultsController *)results {
// If we are not nil, stop here
if (results != nil)
return results;
// Create the fetch request, entity and sort descriptors
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:self.managedObjectContext];
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"utc_start" ascending:YES];
NSArray *descriptors = [[NSArray alloc] initWithObjects:descriptor, nil];
// Set properties on the fetch
[fetch setEntity:entity];
[fetch setSortDescriptors:descriptors];
// Create a fresh fetched results controller
NSFetchedResultsController *fetched = [[NSFetchedResultsController alloc] initWithFetchRequest:fetch managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"day" cacheName:@"Events"];
fetched.delegate = self;
self.results = fetched;
// Release objects and return our controller
[fetched release];
[fetch release];
[descriptor release];
[descriptors release];
return results;
}
These are the messages I get when the app crashes:
这些是我在应用崩溃时收到的信息:
FATAL ERROR: The persistent cache of section information does not match the current configuration. You have illegally mutated the NSFetchedResultsController's fetch request, its predicate, or its sort descriptor without either disabling caching or using +deleteCacheWithName:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'FATAL ERROR: The persistent cache of section information does not match the current configuration. You have illegally mutated the NSFetchedResultsController's fetch request, its predicate, or its sort descriptor without either disabling caching or using +deleteCacheWithName:'
I really have no clue as to why it's saying that, as I don't believe I'm doing anything special that would cause this. The only potential issue is the section header (day), which I construct like this when creating a new object:
我真的不知道为什么会这样说,因为我不相信我做了什么特别的事情会导致这一切。唯一可能的问题是section header (day),我在创建新对象时是这样构造的:
// Set the new format
[formatter setDateFormat:@"dd MMMM"];
// Set the day of the event
[event setValue:[formatter stringFromDate:[event valueForKey:@"utc_start"]] forKey:@"day"];
Like I mentioned, all of this works fine if there is no cache involved. Any help appreciated!
正如我提到的,如果不涉及缓存,所有这些都可以正常工作。任何帮助表示赞赏!
12 个解决方案
#1
65
I had a similar problem with one of my apps, when the Apple released the new iOS 4.0. Search:
当苹果发布新的iOS 4.0时,我的一个应用程序也遇到了类似的问题。搜索:
fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[self managedObjectContext] sectionNameKeyPath:nil cacheName:nil];
And set the value of the parameter cacheName to nil. It worked for me, hope it will for you. Let me know.
并将参数cacheName的值设置为nil。它为我工作,希望它为你。让我知道。
#2
30
I started getting the same error when I upgraded by MacBook Pro to Snow Leopard 10.6.4 and the latest SDK.
当我将MacBook Pro升级到Snow Leopard 10.6.4和最新的SDK时,我也开始犯同样的错误。
As it turns out, many of us had been using code that wasn't in conformance with the rules, but we didn't know it because CoreData wasn't really behaving in accordance with its own rules.
事实证明,我们中的许多人一直在使用不符合规则的代码,但我们不知道,因为CoreData实际上并没有按照它自己的规则行事。
Specifically, when you fetch things, they get cached, and in 4.0, that cache isn't automatically purged in cases where it was purged in the earlier SDK.
具体地说,当你取回东西时,它们会被缓存,在4.0中,当缓存在早期的SDK中被清除时,缓存不会自动被清除。
For me, the solution was simple. I just employed the class method that purges the caches. You can specify an individual entity, but I specify nil so it just does them all in this particular piece of start-up code:
对我来说,解决方法很简单。我只是使用了清除缓存的类方法。你可以指定一个单独的实体,但我指定nil它会在这段启动代码中完成所有这些:
[NSFetchedResultsController deleteCacheWithName:nil];
Suddenly, the little app I've worked on only to familiarize myself with CoreData is working again.
突然,我为熟悉CoreData而编写的小应用程序又开始工作了。
#3
15
Straight from the documentation for NSFetchedResultsController
:
来自NSFetchedResultsController的文档:
Modifying the Fetch Request
修改获取请求
You cannot simply change the fetch request to modify the results. If you want to change the fetch request, you must:
您不能简单地更改fetch请求以修改结果。如果要更改fetch请求,必须:
If you are using a cache, delete it (using
deleteCacheWithName:
). Typically you should not use a cache if you are changing the fetch request.如果您正在使用缓存,请删除它(使用deleteCacheWithName:)。通常,如果要更改fetch请求,则不应该使用缓存。
Change the fetch request.
改变获取请求。
Invoke
performFetch:
.调用performFetch:。
#4
6
I encountered a similar problem. When I inspected the Debugger Console, it showed what the cached objects and the fetched objects were so that I could figure out why they are inconsistent. In my case it was due to a different predicate.
我遇到了类似的问题。当我检查调试器控制台时,它显示了缓存的对象和获取的对象是什么,这样我就可以知道为什么它们是不一致的。在我的例子中,这是由于一个不同的谓词。
Since the values in my predicate are not dynamic, I could specify a different cache name for each predicate. That will create a cache for each 'type' I specify.
由于谓词中的值不是动态的,所以我可以为每个谓词指定不同的缓存名称。这将为我指定的每个“类型”创建一个缓存。
I suppose you will have to assess your need to have the cache. To specify nil, means that a fetch is made in every call.
我想你必须评估你对缓存的需求。要指定nil,意味着每次调用都要进行取回。
I figured out that the error occurs only when the fetch request have some changes. If you are creating a new NSFetchRequest OR changing the predicate OR sort descriptor, then you should delete the cache or use a different cache. Otherwise, ensure that you have the same NSFetchRequest or make sure that your NSFetchedResultsController is retained and that should solve your problem.
我发现只有当fetch请求发生一些更改时才会发生错误。如果您正在创建一个新的NSFetchRequest或更改谓词或排序描述符,那么您应该删除缓存或使用不同的缓存。否则,请确保您有相同的NSFetchRequest,或者确保您的NSFetchedResultsController被保留,这将解决您的问题。
#5
3
If you're using the simulator, try resetting it--I'd guess you've changed your entity map and it's getting confused by a leftover cache. If not, you could try doing what the error says:
如果你在使用模拟器,试着重新设置它——我猜你已经改变了你的实体映射,它被剩下的缓存搞糊涂了。如果没有,你可以试着按照错误说的去做:
- (void)applicationWillTerminate:(UIApplication *)application {
[NSFetchedResultsController deleteCacheNamed:@"Events"];
//etc
}
#6
3
The exception still occurs with Xcode 7 (beta 4):
Xcode 7 (beta 4)仍然存在例外:
You have illegally mutated the NSFetchedResultsController's fetch request, its predicate, or its sort descriptor without either disabling caching or using +deleteCacheWithName:
您已经非法更改了NSFetchedResultsController的fetch请求、它的谓词或它的排序描述符,而没有禁用缓存或使用+deleteCacheWithName:
NOTE: This is with an unmodified Xcode "Template" Master-Detail iOS app with standard Xcode CoreData "boiler-plate" code created with Xcode 7 and using the latest (iOS 9) deployment target.
注意:这是一个未修改的Xcode“Template”母细节iOS应用程序,使用Xcode 7创建的标准Xcode CoreData“boiler-plate”代码,并使用最新的(iOS 9)部署目标。
I noticed it first when I restarted my app in the simulator. I had been starting and stopping the app several times via Xcode and then it happened; and it kept happening. I decided to do some experiments, and the results:
当我在模拟器中重新启动我的应用程序时,我首先注意到了这一点。我已经多次通过Xcode启动和停止app,然后它就发生了;它不停地发生。我决定做一些实验,结果是:
- Every time I stopped the app in the simulator, I would get the exception on a subsequent launch.
- 每次我在模拟器中停止应用程序时,我都会在随后的启动中得到异常。
- Every time I stopped the app using the simulator's Home button, I was able to launch it again successfully.
- 每次我用模拟器的Home键停止这个应用,我就能再次成功地启动它。
The issue can still be fixed as follows, using one or the other of the following methods:
这个问题仍然可以通过以下方法来解决:
- In the AppDelegate's
application didFinishLaunchingWithOptions
method, add the following SwiftNSFetchedResultsController.deleteCacheWithName(nil)
or Objective-C[NSFetchedResultsController deleteCacheWithName:nil];
code. This clears out the corrupted cache. - 在AppDelegate的应用didFinishLaunchingWithOptions方法中,添加以下Swift NSFetchedResultsController.deleteCacheWithName(nil)或Objective-C [NSFetchedResultsController deleteCacheWithName:nil];代码。这将清除损坏的缓存。
- In the Simulator, from the Simulator menu, select Reset Content and Settings. This fixes the problem, but you lose your test data.
- 在模拟器中,从模拟器菜单中选择重置内容和设置。这解决了问题,但是您丢失了测试数据。
I also believe that this is an artifact of running via Xcode and stopping the app prior to it being able to clean up. I've not seen this in the actual device.
我还相信,这是通过Xcode运行并在应用能够清理之前停止的产物。我还没在实际设备中见过。
#7
1
Are you quitting the Simulator using the home button or by terminating the app in Xcode? Maybe the app isn't getting time to finish writing to the cache. Try using the home button to quit the app.
你是用home键退出模拟器,还是用Xcode终止app ?也许应用程序没有时间写完缓存。尝试使用home键退出应用程序。
#8
1
How many classes implement the same - (NSFetchedResultsController *)results method, do you use a different cache for each one? I was having the same issue and I think I fix it by using a different cache name fore some clases since I have different NSPredicates.
有多少类实现了相同的- (NSFetchedResultsController *)结果方法,对每个类使用不同的缓存?我遇到了同样的问题,我想我通过使用不同的缓存名来修复它,因为我有不同的NSPredicates。
#9
1
I was having the same problem.
To fix, I put the [NSFetchedResultsController deleteCacheWithName:@"cacheName"];
before the init of resultsController. Works for me as he only goes there on the first time.
我也有同样的问题。为了修复,我把[NSFetchedResultsController deleteCacheWithName:@“cacheName”];在resultsController的init之前。对我来说,就像他第一次去那里一样。
#10
1
For those who run into the same problem nowadays, the problem is that somehow Core Data doesn't clean the cache so work fine at first time but doesn't after that. Then just put this line right after init the NSFetchRequest
对于现在遇到同样问题的人来说,问题是核心数据不能清理缓存,所以一开始运行得很好,但之后就不行了。然后把这一行放到init NSFetchRequest之后
[NSFetchedResultsController deleteCacheWithName:@"Name"];
#11
1
I found via the Ray Wenderlich forums that
我通过Ray Wenderlich论坛发现
Note that it only crashes when the fetch request is not created yet when you add something new to the datastore, i.e. when the Locations view isn't loaded yet. If the view is loaded already, then it works fine. Odd, eh?
注意,只有在尚未创建fetch请求时才会崩溃,当您向datastore添加新内容时才会崩溃,例如,当还没有加载location视图时。如果视图已经加载,那么它可以正常工作。很奇怪,是吗?
So, what happened in my case was this:
我的情况是这样的:
- The normal launch process entails constructing an NSFetchedResultsController.
- 正常的发射过程需要构建一个NSFetchedResultsController。
- Because there are thousands of objects being fetched, a fresh fetch takes considerable time. To mitigate this, the fetch a) uses a cache, and b) happens in the background, allowing other activities to continue
- 因为有成千上万个对象被获取,一个新的获取需要相当长的时间。为了缓解这种情况,fetch a)使用缓存,b)发生在后台,允许其他活动继续进行
- Normally, though the UI is responsive and the user can do stuff, the fetch is complete long before the user might express a desire to create a new object.
- 通常,虽然UI是响应性的,并且用户可以做一些事情,但是在用户可能表达创建新对象的愿望之前,取回就已经完成了。
- However, sometimes the app will be launched in the background - say, from a WatchKit event, or a background fetch, etc) - and part of the launch will entail creating a new object in the datastore immediately.
- 然而,有时该应用程序将在后台启动——比如,来自WatchKit事件,或后台取回等——并且部分启动将需要立即在datastore中创建一个新对象。
- If the new object was created before the fetch was complete, the app would crash.
- 如果在取回完成之前创建了新对象,应用程序就会崩溃。
The solution is to ensure that The fetch is complete before creating an object (which would affect the fetch).
解决方案是在创建对象(这会影响获取)之前确保获取完成。
Alternatively you could delete the cache, but that is less performant practically speaking.
或者,您可以删除缓存,但这在实际操作中性能较低。
Note that the admonition from the debugger that
请注意调试器中的警告。
You have illegally mutated the NSFetchedResultsController's fetch request, its predicate, or its sort descriptor without either disabling caching or using +deleteCacheWithName:
您已经非法更改了NSFetchedResultsController的fetch请求、它的谓词或它的排序描述符,而没有禁用缓存或使用+deleteCacheWithName:
simply does not capture this situation whatsoever, in that what you have changed was not the request, predicate, or sort descriptor, but rather more accurately could be described as having mutated the result set while the fetch was in progress.
简单地没有捕捉到这种情况,在这种情况下,您所更改的不是请求、谓词或排序描述符,而是更准确地描述为在获取过程中更改了结果集。
It took me forever to track down this tiny piece of trivia. I hope you benefit.
我花了很长时间才找到这个小细节。我希望你的好处。
#12
-2
NSFetchedResultsController *fetched = [[NSFetchedResultsController alloc] initWithFetchRequest:fetch managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"day" cacheName:@"Events"];
replace @"Events" with nil.
@“事件”替换为零。
#1
65
I had a similar problem with one of my apps, when the Apple released the new iOS 4.0. Search:
当苹果发布新的iOS 4.0时,我的一个应用程序也遇到了类似的问题。搜索:
fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[self managedObjectContext] sectionNameKeyPath:nil cacheName:nil];
And set the value of the parameter cacheName to nil. It worked for me, hope it will for you. Let me know.
并将参数cacheName的值设置为nil。它为我工作,希望它为你。让我知道。
#2
30
I started getting the same error when I upgraded by MacBook Pro to Snow Leopard 10.6.4 and the latest SDK.
当我将MacBook Pro升级到Snow Leopard 10.6.4和最新的SDK时,我也开始犯同样的错误。
As it turns out, many of us had been using code that wasn't in conformance with the rules, but we didn't know it because CoreData wasn't really behaving in accordance with its own rules.
事实证明,我们中的许多人一直在使用不符合规则的代码,但我们不知道,因为CoreData实际上并没有按照它自己的规则行事。
Specifically, when you fetch things, they get cached, and in 4.0, that cache isn't automatically purged in cases where it was purged in the earlier SDK.
具体地说,当你取回东西时,它们会被缓存,在4.0中,当缓存在早期的SDK中被清除时,缓存不会自动被清除。
For me, the solution was simple. I just employed the class method that purges the caches. You can specify an individual entity, but I specify nil so it just does them all in this particular piece of start-up code:
对我来说,解决方法很简单。我只是使用了清除缓存的类方法。你可以指定一个单独的实体,但我指定nil它会在这段启动代码中完成所有这些:
[NSFetchedResultsController deleteCacheWithName:nil];
Suddenly, the little app I've worked on only to familiarize myself with CoreData is working again.
突然,我为熟悉CoreData而编写的小应用程序又开始工作了。
#3
15
Straight from the documentation for NSFetchedResultsController
:
来自NSFetchedResultsController的文档:
Modifying the Fetch Request
修改获取请求
You cannot simply change the fetch request to modify the results. If you want to change the fetch request, you must:
您不能简单地更改fetch请求以修改结果。如果要更改fetch请求,必须:
If you are using a cache, delete it (using
deleteCacheWithName:
). Typically you should not use a cache if you are changing the fetch request.如果您正在使用缓存,请删除它(使用deleteCacheWithName:)。通常,如果要更改fetch请求,则不应该使用缓存。
Change the fetch request.
改变获取请求。
Invoke
performFetch:
.调用performFetch:。
#4
6
I encountered a similar problem. When I inspected the Debugger Console, it showed what the cached objects and the fetched objects were so that I could figure out why they are inconsistent. In my case it was due to a different predicate.
我遇到了类似的问题。当我检查调试器控制台时,它显示了缓存的对象和获取的对象是什么,这样我就可以知道为什么它们是不一致的。在我的例子中,这是由于一个不同的谓词。
Since the values in my predicate are not dynamic, I could specify a different cache name for each predicate. That will create a cache for each 'type' I specify.
由于谓词中的值不是动态的,所以我可以为每个谓词指定不同的缓存名称。这将为我指定的每个“类型”创建一个缓存。
I suppose you will have to assess your need to have the cache. To specify nil, means that a fetch is made in every call.
我想你必须评估你对缓存的需求。要指定nil,意味着每次调用都要进行取回。
I figured out that the error occurs only when the fetch request have some changes. If you are creating a new NSFetchRequest OR changing the predicate OR sort descriptor, then you should delete the cache or use a different cache. Otherwise, ensure that you have the same NSFetchRequest or make sure that your NSFetchedResultsController is retained and that should solve your problem.
我发现只有当fetch请求发生一些更改时才会发生错误。如果您正在创建一个新的NSFetchRequest或更改谓词或排序描述符,那么您应该删除缓存或使用不同的缓存。否则,请确保您有相同的NSFetchRequest,或者确保您的NSFetchedResultsController被保留,这将解决您的问题。
#5
3
If you're using the simulator, try resetting it--I'd guess you've changed your entity map and it's getting confused by a leftover cache. If not, you could try doing what the error says:
如果你在使用模拟器,试着重新设置它——我猜你已经改变了你的实体映射,它被剩下的缓存搞糊涂了。如果没有,你可以试着按照错误说的去做:
- (void)applicationWillTerminate:(UIApplication *)application {
[NSFetchedResultsController deleteCacheNamed:@"Events"];
//etc
}
#6
3
The exception still occurs with Xcode 7 (beta 4):
Xcode 7 (beta 4)仍然存在例外:
You have illegally mutated the NSFetchedResultsController's fetch request, its predicate, or its sort descriptor without either disabling caching or using +deleteCacheWithName:
您已经非法更改了NSFetchedResultsController的fetch请求、它的谓词或它的排序描述符,而没有禁用缓存或使用+deleteCacheWithName:
NOTE: This is with an unmodified Xcode "Template" Master-Detail iOS app with standard Xcode CoreData "boiler-plate" code created with Xcode 7 and using the latest (iOS 9) deployment target.
注意:这是一个未修改的Xcode“Template”母细节iOS应用程序,使用Xcode 7创建的标准Xcode CoreData“boiler-plate”代码,并使用最新的(iOS 9)部署目标。
I noticed it first when I restarted my app in the simulator. I had been starting and stopping the app several times via Xcode and then it happened; and it kept happening. I decided to do some experiments, and the results:
当我在模拟器中重新启动我的应用程序时,我首先注意到了这一点。我已经多次通过Xcode启动和停止app,然后它就发生了;它不停地发生。我决定做一些实验,结果是:
- Every time I stopped the app in the simulator, I would get the exception on a subsequent launch.
- 每次我在模拟器中停止应用程序时,我都会在随后的启动中得到异常。
- Every time I stopped the app using the simulator's Home button, I was able to launch it again successfully.
- 每次我用模拟器的Home键停止这个应用,我就能再次成功地启动它。
The issue can still be fixed as follows, using one or the other of the following methods:
这个问题仍然可以通过以下方法来解决:
- In the AppDelegate's
application didFinishLaunchingWithOptions
method, add the following SwiftNSFetchedResultsController.deleteCacheWithName(nil)
or Objective-C[NSFetchedResultsController deleteCacheWithName:nil];
code. This clears out the corrupted cache. - 在AppDelegate的应用didFinishLaunchingWithOptions方法中,添加以下Swift NSFetchedResultsController.deleteCacheWithName(nil)或Objective-C [NSFetchedResultsController deleteCacheWithName:nil];代码。这将清除损坏的缓存。
- In the Simulator, from the Simulator menu, select Reset Content and Settings. This fixes the problem, but you lose your test data.
- 在模拟器中,从模拟器菜单中选择重置内容和设置。这解决了问题,但是您丢失了测试数据。
I also believe that this is an artifact of running via Xcode and stopping the app prior to it being able to clean up. I've not seen this in the actual device.
我还相信,这是通过Xcode运行并在应用能够清理之前停止的产物。我还没在实际设备中见过。
#7
1
Are you quitting the Simulator using the home button or by terminating the app in Xcode? Maybe the app isn't getting time to finish writing to the cache. Try using the home button to quit the app.
你是用home键退出模拟器,还是用Xcode终止app ?也许应用程序没有时间写完缓存。尝试使用home键退出应用程序。
#8
1
How many classes implement the same - (NSFetchedResultsController *)results method, do you use a different cache for each one? I was having the same issue and I think I fix it by using a different cache name fore some clases since I have different NSPredicates.
有多少类实现了相同的- (NSFetchedResultsController *)结果方法,对每个类使用不同的缓存?我遇到了同样的问题,我想我通过使用不同的缓存名来修复它,因为我有不同的NSPredicates。
#9
1
I was having the same problem.
To fix, I put the [NSFetchedResultsController deleteCacheWithName:@"cacheName"];
before the init of resultsController. Works for me as he only goes there on the first time.
我也有同样的问题。为了修复,我把[NSFetchedResultsController deleteCacheWithName:@“cacheName”];在resultsController的init之前。对我来说,就像他第一次去那里一样。
#10
1
For those who run into the same problem nowadays, the problem is that somehow Core Data doesn't clean the cache so work fine at first time but doesn't after that. Then just put this line right after init the NSFetchRequest
对于现在遇到同样问题的人来说,问题是核心数据不能清理缓存,所以一开始运行得很好,但之后就不行了。然后把这一行放到init NSFetchRequest之后
[NSFetchedResultsController deleteCacheWithName:@"Name"];
#11
1
I found via the Ray Wenderlich forums that
我通过Ray Wenderlich论坛发现
Note that it only crashes when the fetch request is not created yet when you add something new to the datastore, i.e. when the Locations view isn't loaded yet. If the view is loaded already, then it works fine. Odd, eh?
注意,只有在尚未创建fetch请求时才会崩溃,当您向datastore添加新内容时才会崩溃,例如,当还没有加载location视图时。如果视图已经加载,那么它可以正常工作。很奇怪,是吗?
So, what happened in my case was this:
我的情况是这样的:
- The normal launch process entails constructing an NSFetchedResultsController.
- 正常的发射过程需要构建一个NSFetchedResultsController。
- Because there are thousands of objects being fetched, a fresh fetch takes considerable time. To mitigate this, the fetch a) uses a cache, and b) happens in the background, allowing other activities to continue
- 因为有成千上万个对象被获取,一个新的获取需要相当长的时间。为了缓解这种情况,fetch a)使用缓存,b)发生在后台,允许其他活动继续进行
- Normally, though the UI is responsive and the user can do stuff, the fetch is complete long before the user might express a desire to create a new object.
- 通常,虽然UI是响应性的,并且用户可以做一些事情,但是在用户可能表达创建新对象的愿望之前,取回就已经完成了。
- However, sometimes the app will be launched in the background - say, from a WatchKit event, or a background fetch, etc) - and part of the launch will entail creating a new object in the datastore immediately.
- 然而,有时该应用程序将在后台启动——比如,来自WatchKit事件,或后台取回等——并且部分启动将需要立即在datastore中创建一个新对象。
- If the new object was created before the fetch was complete, the app would crash.
- 如果在取回完成之前创建了新对象,应用程序就会崩溃。
The solution is to ensure that The fetch is complete before creating an object (which would affect the fetch).
解决方案是在创建对象(这会影响获取)之前确保获取完成。
Alternatively you could delete the cache, but that is less performant practically speaking.
或者,您可以删除缓存,但这在实际操作中性能较低。
Note that the admonition from the debugger that
请注意调试器中的警告。
You have illegally mutated the NSFetchedResultsController's fetch request, its predicate, or its sort descriptor without either disabling caching or using +deleteCacheWithName:
您已经非法更改了NSFetchedResultsController的fetch请求、它的谓词或它的排序描述符,而没有禁用缓存或使用+deleteCacheWithName:
simply does not capture this situation whatsoever, in that what you have changed was not the request, predicate, or sort descriptor, but rather more accurately could be described as having mutated the result set while the fetch was in progress.
简单地没有捕捉到这种情况,在这种情况下,您所更改的不是请求、谓词或排序描述符,而是更准确地描述为在获取过程中更改了结果集。
It took me forever to track down this tiny piece of trivia. I hope you benefit.
我花了很长时间才找到这个小细节。我希望你的好处。
#12
-2
NSFetchedResultsController *fetched = [[NSFetchedResultsController alloc] initWithFetchRequest:fetch managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"day" cacheName:@"Events"];
replace @"Events" with nil.
@“事件”替换为零。