核心数据:'谓词的未实现SQL生成:(列IN {value1,value2})'

时间:2017-05-15 14:39:15

标签: ios swift core-data nspredicate

我无法在NSPredicate中实现 IN 。我收到了这个错误。我检查了一切,但还没有解决这个问题。有没有人发现类似的问题?

这是我的模特

enter image description here

以下是我正在执行的代码

let messageLocalFetchRequest = NSFetchRequest<NSFetchRequestResult>.init(entityName: "Transaction")
messageLocalFetchRequest.predicate =  NSPredicate.init(format: "category IN %@", ["Food","Rent"])
let array = try? self.context?.fetch(messageLocalFetchRequest)

这里有完整的日志

2017-05-15 19:31:33.985 BudgetApp[26354:184185] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (category IN {"Food", "Rent"})'
*** First throw call stack:
(
    0   CoreFoundation                      0x01719ded __exceptionPreprocess + 189
    1   libobjc.A.dylib                     0x00dfad6f objc_exception_throw + 49
    2   CoreData                            0x0138266e -[NSSQLGenerator newSQLStatementForRequest:ignoreInheritance:countOnly:nestingLevel:nestIsWhereScoped:requestContext:] + 1710
    3   CoreData                            0x013826b1 -[NSSQLGenerator newSQLStatementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:nestIsWhereScoped:requestContext:] + 49
    4   CoreData                            0x0138c1ce -[NSSQLiteAdapter _statementForFetchRequestContext:ignoreInheritance:countOnly:nestingLevel:] + 206
    5   CoreData                            0x0126256e -[NSSQLiteAdapter newSelectStatementWithFetchRequestContext:ignoreInheritance:] + 158
    6   CoreData                            0x013b91cb -[NSSQLFetchRequestContext _createStatement] + 75
    7   CoreData                            0x013b913d -[NSSQLFetchRequestContext fetchStatement] + 45
    8   CoreData                            0x013ba540 -[NSSQLFetchRequestContext executeRequestUsingConnection:] + 64
    9   CoreData                            0x013e76d3 __52-[NSSQLDefaultConnectionManager handleStoreRequest:]_block_invoke + 275
    10  libdispatch.dylib                   0x05473cc9 _dispatch_client_callout + 14
    11  libdispatch.dylib                   0x0544fac4 _dispatch_barrier_sync_f_invoke + 180
    12  libdispatch.dylib                   0x0544f82b dispatch_barrier_sync_f + 157
    13  libdispatch.dylib                   0x0544fbb8 dispatch_sync + 41
    14  CoreData                            0x013e7571 -[NSSQLDefaultConnectionManager handleStoreRequest:] + 241
    15  CoreData                            0x013eec7a -[NSSQLCoreDispatchManager routeStoreRequest:] + 282
    16  CoreData                            0x0136e645 -[NSSQLCore dispatchRequest:withRetries:] + 213
    17  CoreData                            0x0136b421 -[NSSQLCore processFetchRequest:inContext:] + 113
    18  CoreData                            0x01261b31 -[NSSQLCore executeRequest:withContext:error:] + 465
    19  CoreData                            0x01354481 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 2769
    20  CoreData                            0x0134c3e5 -[NSPersistentStoreCoordinator _routeHeavyweightBlock:] + 341
    21  CoreData                            0x01261703 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 579
    22  CoreData                            0x0125fb93 -[NSManagedObjectContext executeFetchRequest:error:] + 675
    23  BudgetApp                           0x000d0cfb _TFC9BudgetApp30TransactionTableViewController11viewDidLoadfT_T_ + 2059
    24  BudgetApp                           0x000d1052 _TToFC9BudgetApp30TransactionTableViewController11viewDidLoadfT_T_ + 34
    25  UIKit                               0x025ef61c -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 38
    26  UIKit                               0x025f3fa5 -[UIViewController loadViewIfRequired] + 1434
    27  UIKit                               0x026386b4 -[UINavigationController _layoutViewController:] + 52
    28  UIKit                               0x02638f57 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 427
    29  UIKit                               0x026390e6 -[UINavigationController _startTransition:fromViewController:toViewController:] + 123
    30  UIKit                               0x0263a26d -[UINavigationController _startDeferredTransitionIfNeeded:] + 979
    31  UIKit                               0x0263b698 -[UINavigationController __viewWillLayoutSubviews] + 70
    32  UIKit                               0x02852fd9 -[UILayoutContainerView layoutSubviews] + 235
    33  UIKit                               0x024fdb23 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1418
    34  libobjc.A.dylib                     0x00e101d9 -[NSObject performSelector:withObject:] + 59
    35  QuartzCore                          0x022b50ea -[CALayer layoutSublayers] + 141
    36  QuartzCore                          0x022a8486 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 398
    37  QuartzCore                          0x022a82e3 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 21
    38  QuartzCore                          0x02234a92 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 334
    39  QuartzCore                          0x02261f8f _ZN2CA11Transaction6commitEv + 483
    40  QuartzCore                          0x02263b60 _ZN2CA11Transaction17flush_transactionEv + 38
    41  UIKit                               0x024233a7 _UIApplicationFlushRunLoopCATransactionIfTooLate + 182
    42  UIKit                               0x02cbe95e __handleEventQueue + 2054
    43  UIKit                               0x02cbfba3 __handleHIDEventFetcherDrain + 66
    44  CoreFoundation                      0x016bea5f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    45  CoreFoundation                      0x016a41c4 __CFRunLoopDoSources0 + 500
    46  CoreFoundation                      0x016a369c __CFRunLoopRun + 1084
    47  CoreFoundation                      0x016a2fd4 CFRunLoopRunSpecific + 372
    48  CoreFoundation                      0x016a2e4b CFRunLoopRunInMode + 123
    49  GraphicsServices                    0x070f7a7a GSEventRunModal + 71
    50  GraphicsServices                    0x070f795f GSEventRun + 80
    51  UIKit                               0x0242acb9 UIApplicationMain + 148
    52  BudgetApp                           0x000bc59b main + 75
    53  libdyld.dylib                       0x054ae779 start + 1
    54  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

1 个答案:

答案 0 :(得分:0)

字符串是对象,因此您无法使用IN

<强>目标C

[NSPredicate predicateWithFormat:@"ANY %@ LIKE[cd] category", @[@"Food",@"Rent"]]

Swift 3.1

NSPredicate(format: "ANY %@ LIKE[cd] category", ["Food", "Rent"])