iOS结果类型‘Element’不匹配预期类型(Swift - Coredata)

时间:2020-12-18 16:34:29

Using Xcode 7.0 and Swift 2

使用Xcode 7.0和Swift 2

I am trying to execute a fetchrequest in CoreData but is not working.

我正在尝试在CoreData中执行fetchrequest,但是没有工作。

Getting the below error. Not sure what the issue is. "segmentedControl" is an outlet from a segmentedControl view.

得到以下错误。不知道这个问题是什么。“segmentedControl”是一个来自segmentedControl视图的出口。

iOS结果类型‘Element’不匹配预期类型(Swift - Coredata)

The strange bit is that I have used similar code in another sample project and there were no issues. Below is that code snippet

奇怪的是,我在另一个示例项目中使用了类似的代码,没有问题。下面是代码片段

iOS结果类型‘Element’不匹配预期类型(Swift - Coredata)

I have used the execute fetchrequest syntax based on this post

基于本文,我使用了execute fetchrequest语法

1 个解决方案

#1


1  

Use breakpoints or print statements to examine the value of firstTitle!. If it is not a string, and title in your entity is not defined as a String type, you will get this error.

使用断点或打印语句检查firstTitle的值!如果它不是字符串,并且实体中的标题没有定义为字符串类型,您将得到这个错误。

Also, make sure that your segmented control is set up as expected.

另外,确保您的分段控件按照预期设置。

#1


1  

Use breakpoints or print statements to examine the value of firstTitle!. If it is not a string, and title in your entity is not defined as a String type, you will get this error.

使用断点或打印语句检查firstTitle的值!如果它不是字符串,并且实体中的标题没有定义为字符串类型,您将得到这个错误。

Also, make sure that your segmented control is set up as expected.

另外,确保您的分段控件按照预期设置。