本文介绍了类型“AnyObject”不符合协议'NSFetchRequestResult'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装了 Xcode 8 beta 2 iOS 10 beta 。我有一个现有的项目,我从swift 2.3更新到swift 3基于Xcode的提示。我收到我的代码数据代码的错误。



这是由xcode从swift 2.3转换为swift 3时自动产生的

  var fetchedResultsController:NSFetchedResultsController< AnyObject> ;! 

我收到的错误是

 类型AnyObject不符合协议'NSFetchRequestResult'

我尝试符合AnyObject

 扩展AnyObject:NSFetchRequestResult {} 

但我收到另一个错误





我不知道我需要做什么,或者如果我的fetchedResultsController需要改变在第一位。



ANSWER: var fetchedResultsController:NSFetchedResultsController< Content>!

Entity 感到困惑。用您要提取的实体类型替换 AnyObject



您应该打开一个雷达(bugreporter.apple.com)因为它不应该在这里建议 AnyObject 。在最坏的情况下,它应该建议 NSManagedObject


I just installed Xcode 8 beta 2 and iOS 10 beta. I have an existing project where I updated from swift 2.3 to swift 3 based on a prompt from Xcode. I received an error with my code data code.

This was auto generated in the conversion from swift 2.3 to swift 3 by xcode

var fetchedResultsController: NSFetchedResultsController<AnyObject>!

the error I'm receiving is

 Type 'AnyObject' does not conform to protocol 'NSFetchRequestResult'

I tried to conform AnyObject

extension AnyObject: NSFetchRequestResult {}

But I receive another error

I am not sure what I need to do or if my fetchedResultsController needs to be changed in the first place.

ANSWER: var fetchedResultsController: NSFetchedResultsController<Content>!

解决方案

The Xcode converter likely was confused about what Entity you wanted to return in this fetched results controller. Replace AnyObject with the entity type you are fetching.

You should open a radar (bugreporter.apple.com) on this, since it should never suggest AnyObject here. At worst it should suggest NSManagedObject.

这篇关于类型“AnyObject”不符合协议'NSFetchRequestResult'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 04:03