Swift executeFetchRequest-错误:无法识别的选择器已发送到实例

Swift executeFetchRequest-错误:无法识别的选择器已发送到实例,swift,core-data,unrecognized-selector,Swift,Core Data,Unrecognized Selector,我是一名C#软件开发人员,所以我知道如何在Windows上编程,但我对OSX、XCode和Swift完全是新手 我编写了一段代码,使用名为“SharesEntity”的核心数据实体,并尝试使用NSExpression来确定名为“sorrend”(order)的属性的最大值。但是当我执行代码时,我得到一个错误: “已将无法识别的选择器发送到实例0x127” 此处出现错误:请尝试orderResults=context!。executeFetchRequest(orderRequest) 错误堆栈:

我是一名C#软件开发人员,所以我知道如何在Windows上编程,但我对OSX、XCode和Swift完全是新手

我编写了一段代码,使用名为“SharesEntity”的核心数据实体,并尝试使用NSExpression来确定名为“sorrend”(order)的属性的最大值。但是当我执行代码时,我得到一个错误:

“已将无法识别的选择器发送到实例0x127”

此处出现错误:请尝试orderResults=context!。executeFetchRequest(orderRequest)

错误堆栈:

Printing description of orderRequest:
<NSFetchRequest: 0x6100000cce10> (entity: SharesEntity; predicate: ((null)); sortDescriptors: ((null)); type: NSDictionaryResultType; includesPendingChanges: NO; propertiesToFetch: ((
"(<NSExpressionDescription: 0x610000163a80>), name maxSorrend, isOptional 1, isTransient 0, entity (null), renamingIdentifier maxSorrend, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}"
)); )
2016-04-23 17:30:33.436 iShares[2448:156683] -[__NSCFNumber count]: unrecognized selector sent to instance 0x127
2016-04-23 17:30:33.437 iShares[2448:156683] -[__NSCFNumber count]: unrecognized selector sent to instance 0x127
2016-04-23 17:30:33.440 iShares[2448:156683] (
0   CoreFoundation                      0x00007fff82e284f2 __exceptionPreprocess + 178
1   libobjc.A.dylib                     0x00007fff97b22f7e objc_exception_throw + 48
2   CoreFoundation                      0x00007fff82e921ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3   CoreFoundation                      0x00007fff82d98571 ___forwarding___ + 1009
4   CoreFoundation                      0x00007fff82d980f8 _CF_forwarding_prep_0 + 120
5   Foundation                          0x00007fff899f8579 +[_NSPredicateUtilities max:] + 56
6   Foundation                          0x00007fff8981c5fb -[NSFunctionExpression expressionValueWithObject:context:] + 1094
7   CoreData                            0x00007fff90648f8a -[NSMappedObjectStore executeFetchRequest:withContext:] + 2122
8   CoreData                            0x00007fff906a3288 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 4120
9   CoreData                            0x00007fff906adb63 gutsOfBlockToNSPersistentStoreCoordinatorPerform + 179
10  libdispatch.dylib                   0x00000001005cdcc5 _dispatch_client_callout + 8
11  libdispatch.dylib                   0x00000001005cf3db _dispatch_barrier_sync_f_invoke + 375
12  CoreData                            0x00007fff9069c662 _perform + 194
13  CoreData                            0x00007fff905e05c5 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 533
14  CoreData                            0x00007fff905ded4a -[NSManagedObjectContext executeFetchRequest:error:] + 586
15  iShares                             0x00000001000040a7 _TFC7iShares14ViewController7sorrendfT_T_ + 1047
16  iShares                             0x0000000100002ee0 _TFC7iShares14ViewController9hozzaadasfPs9AnyObject_T_ + 64
17  iShares                             0x0000000100003c76 _TToFC7iShares14ViewController9hozzaadasfPs9AnyObject_T_ + 54
18  libsystem_trace.dylib               0x00007fff92e1707a _os_activity_initiate + 75
19  AppKit                              0x00007fff8c7fce89 -[NSApplication sendAction:to:from:] + 460
20  AppKit                              0x00007fff8c80efde -[NSControl sendAction:to:] + 86
21  AppKit                              0x00007fff8c80ef08 __26-[NSCell _sendActionFrom:]_block_invoke + 131
22  libsystem_trace.dylib               0x00007fff92e1707a _os_activity_initiate + 75
23  AppKit                              0x00007fff8c80ee65 -[NSCell _sendActionFrom:] + 144
24  libsystem_trace.dylib               0x00007fff92e1707a _os_activity_initiate + 75
25  AppKit                              0x00007fff8c80d48a -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2693
26  AppKit                              0x00007fff8c855fd0 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 744
27  AppKit                              0x00007fff8c80bbb4 -[NSControl mouseDown:] + 669
28  AppKit                              0x00007fff8cd60469 -[NSWindow _handleMouseDownEvent:isDelayedEvent:] + 6322
29  AppKit                              0x00007fff8cd6144d -[NSWindow _reallySendEvent:isDelayedEvent:] + 212
30  AppKit                              0x00007fff8c7a063d -[NSWindow sendEvent:] + 517
31  AppKit                              0x00007fff8c720b3c -[NSApplication sendEvent:] + 2540
32  AppKit                              0x00007fff8c587ef6 -[NSApplication run] + 796
33  AppKit                              0x00007fff8c55146c NSApplicationMain + 1176
34  iShares                             0x000000010000b264 main + 84
35  libdyld.dylib                       0x00007fff921315ad start + 1
36  ???                                 0x0000000000000003 0x0 + 3
)
打印订单请求的说明: (实体:ShareSenty;谓词:((null));排序描述符:((null));类型:NSDictionaryResultType;includesPendingChanges:否;propertiesToFetch:(( (),名称maxSorrend,isOptional 1,isTransient 0,实体(null),重命名标识符maxSorrend,验证谓词(\n),警告(\n),版本HashModifier(null)\n用户信息{\n} )); ) 2016-04-23 17:30:33.436 iShares[2448:156683]-[\uu NSCFNumber count]:发送到实例0x127的无法识别的选择器 2016-04-23 17:30:33.437 iShares[2448:156683]-[\uu NSCFNumber count]:发送到实例0x127的无法识别的选择器 2016-04-23 17:30:33.440 iShares[2448:156683]( 0 CoreFoundation 0x00007fff82e284f2例外预处理+178 1 libobjc.A.dylib 0x00007fff97b22f7e objc_异常_抛出+48 2 CoreFoundation 0x00007fff82e921ad-[NSObject(NSObject)未识别选择器:+205 3 CoreFoundation 0x00007fff82d98571 ____;转发_;+1009 4 CoreFoundation 0x00007fff82d980f8 _CF_转发_准备_0+120 5基金会0x000 7FFF899F857 9+ [αNSPReDeCuditILITY MAX:] + 56 6基金会0x000 7FFF8981C5FB-[ NSCONTRONTRONEXPROSPECTIONEXPRESS ValueObjult:Currase:] + 1094 7 CoreData 0x00007fff90648f8a-[NSMappedObjectStore executeFetchRequest:withContext:+2122 8 CoreData 0x00007fff906a3288\uu 65-[NSPersistentStoreCoordinator executeRequest:withContext:error:][u block\u invoke+4120 9 CoreData 0x00007fff906adb63块体槽口分离器存储协调器性能+179 10 libdispatch.dylib 0x00000001005cdcc5调度客户端调用+8 11 libdispatch.dylib 0x00000001005cf3db\u dispatch\u barrier\u sync\u f\u invoke+375 12 CoreData 0x00007fff9069c662执行+194 13 CoreData 0x00007fff905e05c5-[NSPersistentStoreCoordinator executeRequest:withContext:error:+533 14 CoreData 0x00007fff905ded4a-[NSManagedObjectContext executeFetchRequest:错误:][586 15 iShares 0x00000001000040a7\u TFC7 iShares 14视图控制器7 Sorrendft\u T\u+1047 16 iShares 0x0000000100002ee0\u TFC7 iShares 14视图控制器9Hozzaadasfps9AnyObject\u T\u64 17 iShares 0x0000000100003c76\u TTOFC7 iShares 14视图控制器9HOZZAADASFPS9AnyObject\u T\u54 18 libsystem_trace.dylib 0x00007fff92e1707a_os_activity_initiate+75 19应用套件0x00007fff8c7fce89-[N应用程序发送操作:到:从:][460 20应用套件0x00007fff8c80efde-[NSControl sendAction:to::::+86 21应用套件0x00007fff8c80ef08 \uuuu 26-[NSCell\u sendActionFrom:]\u block\u invoke+131 22 libsystem_trace.dylib 0x00007fff92e1707a_os_activity_initiate+75 23应用套件0x00007fff8c80ee65-[NSCell\u sendActionFrom:][144 24 libsystem_trace.dylib 0x00007fff92e1707a_os_activity_initiate+75 25应用套件0x00007fff8c80d48a-[NSCell trackMouse:inRect:ofView:untillmouseup:+2693 26应用套件0x00007fff8c855fd0-[NSButtonCell轨迹鼠标:输入:ofView:UntillMouseUp:+744 27应用套件0x00007fff8c80bbb4-[NSControl mouseDown:][669 28应用套件0x00007fff8cd60469-[NSWindow\U handleMouseDownEvent:isDelayedEvent:+6322 29应用套件0x00007fff8cd6144d-[NSWindow\u reallysendent:isDelayedEvent:+212 30应用套件0x00007fff8c7a063d-[NSWindow sendEvent::+517 31应用套件0x00007fff8c720b3c-[NSApplication sendEvent:+2540 32应用套件0x00007fff8c587ef6-[N应用程序运行]+796 33应用套件0x00007fff8c55146c NSApplicationMain+1176 34 iShares 0x000000010000b264主+84 35 libdyld.dylib 0x00007fff921315ad开始+1 36°?0x0000000000000003 0x0+3 ) +[\u NSPredicateUtilities max:]的断点结果:

Foundation`+[_NSPredicateUtilities max:]:
0x7fff899f8541 <+0>:    pushq  %rbp                      ; this line was highlighted

0x7fff899f8542 <+1>:    movq   %rsp, %rbp
0x7fff899f8545 <+4>:    pushq  %r15
0x7fff899f8547 <+6>:    pushq  %r14
0x7fff899f8549 <+8>:    pushq  %r13
0x7fff899f854b <+10>:   pushq  %r12
0x7fff899f854d <+12>:   pushq  %rbx
0x7fff899f854e <+13>:   subq   $0x258, %rsp              ; imm = 0x258 
0x7fff899f8555 <+20>:   movq   %rdx, %r14
0x7fff899f8558 <+23>:   movq   %rdi, %rbx
0x7fff899f855b <+26>:   movq   -0x163ec1da(%rip), %rax   ; (void *)0x00007fff735cc070: __stack_chk_guard
0x7fff899f8562 <+33>:   movq   (%rax), %rax
0x7fff899f8565 <+36>:   movq   %rax, -0x30(%rbp)
0x7fff899f8569 <+40>:   movq   -0x163336d0(%rip), %rsi   ; "count"
0x7fff899f8570 <+47>:   movq   %r14, %rdi
0x7fff899f8573 <+50>:   callq  *-0x163ebbf9(%rip)        ; (void *)0x00007fff97b134c0: objc_msgSend
0x7fff899f8579 <+56>:   testq  %rax, %rax
0x7fff899f857c <+59>:   je     0x7fff899f8947            ; <+1030>
0x7fff899f8582 <+65>:   movq   -0x1632cf79(%rip), %rsi   ; "_getCommonTypeFor:"
0x7fff899f8589 <+72>:   movq   -0x163ebc10(%rip), %r15   ; (void *)0x00007fff97b134c0: objc_msgSend
...
Foundation`+[\u NSPredicateUtilities max:]:
0x7fff899f8541:pushq%rbp;这一行被突出显示
0x7fff899f8542:movq%rsp,%rbp
0x7fff899f8545:pushq%r15
0x7fff899f8547:pushq%r14
0x7fff899f8549:pushq%r13
0x7fff899f854b:pushq%r12
0x7fff899f854d:pushq%rbx
0x7fff899f854e:subq$0x258,%rsp;imm=0x258
0x7fff899f8555:movq%rdx,%r14
0x7fff899f8558:movq%rdi,%rbx
0x7fff899f855b:movq-0x163ec1da(%rip),%rax;(无效*)0x00007fff735cc070:\u堆栈\u chk\u防护
0x7fff899f8562:movq(%rax),%rax
0x7fff899f8565:movq%rax,-0x30(%rbp)
0x7fff899f8569:movq-0x163336d0(%rip),%rsi;“计数”
0x7fff899f8570:movq%r14,%rdi
0x7fff899f8573:callq*-0x163ebbf9(%rip);(无效*)0x00007fff97b134c0:objc_msgSend
0x7fff899f8579:testq%rax,%rax
0x7fff899f857c:je 0x7fff899f8947;
0x7fff899f8582:movq-0x1632cf79(%rip),
Foundation`+[_NSPredicateUtilities max:]:
0x7fff899f8541 <+0>:    pushq  %rbp                      ; this line was highlighted

0x7fff899f8542 <+1>:    movq   %rsp, %rbp
0x7fff899f8545 <+4>:    pushq  %r15
0x7fff899f8547 <+6>:    pushq  %r14
0x7fff899f8549 <+8>:    pushq  %r13
0x7fff899f854b <+10>:   pushq  %r12
0x7fff899f854d <+12>:   pushq  %rbx
0x7fff899f854e <+13>:   subq   $0x258, %rsp              ; imm = 0x258 
0x7fff899f8555 <+20>:   movq   %rdx, %r14
0x7fff899f8558 <+23>:   movq   %rdi, %rbx
0x7fff899f855b <+26>:   movq   -0x163ec1da(%rip), %rax   ; (void *)0x00007fff735cc070: __stack_chk_guard
0x7fff899f8562 <+33>:   movq   (%rax), %rax
0x7fff899f8565 <+36>:   movq   %rax, -0x30(%rbp)
0x7fff899f8569 <+40>:   movq   -0x163336d0(%rip), %rsi   ; "count"
0x7fff899f8570 <+47>:   movq   %r14, %rdi
0x7fff899f8573 <+50>:   callq  *-0x163ebbf9(%rip)        ; (void *)0x00007fff97b134c0: objc_msgSend
0x7fff899f8579 <+56>:   testq  %rax, %rax
0x7fff899f857c <+59>:   je     0x7fff899f8947            ; <+1030>
0x7fff899f8582 <+65>:   movq   -0x1632cf79(%rip), %rsi   ; "_getCommonTypeFor:"
0x7fff899f8589 <+72>:   movq   -0x163ebc10(%rip), %r15   ; (void *)0x00007fff97b134c0: objc_msgSend
...