Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios swift中的动态投射错误_Ios_Core Data_Swift - Fatal编程技术网

Ios swift中的动态投射错误

Ios swift中的动态投射错误,ios,core-data,swift,Ios,Core Data,Swift,目前,我正在尝试遍历包含NSManagedObject的NSArray。 当我试图强制转换获取的对象时,它会向我抛出一个错误。 这是密码 for var i = 0; i < self.displayedHistoryListContent.count ; i=i+1{ var productObject: Product = self.displayedHistoryListContent.objectAtIndex(i) as Product }

目前,我正在尝试遍历包含NSManagedObject的NSArray。 当我试图强制转换获取的对象时,它会向我抛出一个错误。 这是密码

for var i = 0; i < self.displayedHistoryListContent.count ; i=i+1{
            var productObject: Product = self.displayedHistoryListContent.objectAtIndex(i) as Product
        }
产品是我的管理对象

应用程序在我进行“作为产品”铸造的生产线上崩溃


有人能告诉我哪里出了问题吗?

看起来您的阵列并不仅仅包含产品。用as试一试?而不是为了证实这一点。当您需要产品时,可以使用NSLog查看阵列中的内容。

您确定阵列中的对象实际上是类产品吗?在处理NSManagedObject时,很容易混淆并引用集合而不是对象本身。 你可能知道演员阵容不是一种转化


使用println查看什么类型的对象确实在那里

你有哪种错误?-1:这是你的第12个问题,你应该知道如何格式化你的问题。这种方式很难读懂代码。您还没有发布错误消息。如果你对你的问题下了功夫,我们为什么要回答呢?libswiftCore.dylib`swift_dynamiccastobjcclass无条件:0x409678:push{r4,r7,lr}0x40967a:mov r4,r0 0x40967c:mov r2,r1 0x40967e:add r7,sp,0x4 0x409680:cmp r4,0x0 0x409682:beq 0x40969e;swift_dynamiccastobjcclassr1+38 0x409684:movw r0,0x8b8c 0x409688:movt r0,0x1 0x40968c:add r0,pc 0x40968e:ldr r1,[r0]0x409690:mov r0,r4objc_msgSend 0x409696:tst.w r0,0xff 0x40969a:bne 0x4096a0;swift_dynamiccastobjcclass+40Hi-Rien,是的,它确实包含产品NSManagedObject,因为它在我的表视图中正确显示了重载数据。这不是为了说明问题,但运行时不同意您的意见,您尝试过PrintLObject吗?