- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 CoreData 中,我想通过一个键获取一个元素。然而,执行获取请求会导致 unrecognized selector sent to instance
。我的代码摘录如下所示,在最后一行失败。 managedObjectContext
是一个有效的实例,因为我也是插入新实例的那个。这会不会是与 Swift 的 Int64
和 CoreData 的 Integer 64 不兼容?
var error : NSError?
var request = NSFetchRequest(entityName: "Node")
var nodeId = NSNumber(longLong: Int64(46763376))
request.predicate = NSPredicate(format: "id = %@", [nodeId])
var nodes = managedObjectContext.executeFetchRequest(request, error: &error)
数据模型中的实体定义:
节点实体在 Swift 中定义为:
class Node : NSManagedObject {
@NSManaged var id: NSNumber
@NSManaged var lat: NSNumber
@NSManaged var lon: NSNumber
@NSManaged var tags: NSMutableSet
@NSManaged var ways: NSMutableSet
func description() -> String {
return "Node(id=\(id), lat=\(lat), lon=\(lon))"
}
}
堆栈跟踪:
2014-06-30 08:27:58.238 SwiftApp[35316:1660108] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_TtCSs22ContiguousArrayStorage000000000B6E69C4 longLongValue]: unrecognized selector sent to instance 0xd7d0018'
*** First throw call stack:
(
0 CoreFoundation 0x00864646 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x0218f8e3 objc_exception_throw + 44
2 CoreFoundation 0x0086b575 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x007b6407 ___forwarding___ + 1047
4 CoreFoundation 0x007b5fce _CF_forwarding_prep_0 + 14
5 CoreData 0x0035a125 -[NSSQLiteConnection execute] + 1349
6 CoreData 0x0036e197 -[NSSQLChannel selectRowsWithStatement:] + 119
7 CoreData 0x0037767d newFetchedRowsForFetchPlan_MT + 1741
8 CoreData 0x00362723 -[NSSQLCore newRowsForFetchPlan:] + 403
9 CoreData 0x00361d85 -[NSSQLCore objectsForFetchRequest:inContext:] + 709
10 CoreData 0x00361740 -[NSSQLCore executeRequest:withContext:error:] + 448
11 CoreData 0x0045c6a5 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 2917
12 CoreData 0x00465be8 internalBlockToNSPersistentStoreCoordinatorPerform + 72
13 libdispatch.dylib 0x026a6488 _dispatch_client_callout + 14
14 libdispatch.dylib 0x0268ea38 _dispatch_barrier_sync_f_invoke + 124
15 libdispatch.dylib 0x0268e2c0 dispatch_barrier_sync_f + 89
16 CoreData 0x004574b3 _perform + 99
17 CoreData 0x00361345 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 1525
18 CoreData 0x0035f575 -[NSManagedObjectContext executeFetchRequest:error:] + 597
19 SwiftApp 0x000189b6 _TFC8SwiftApp11AppDelegate6parserfS0_FTGSQCSo11NSXMLParser_15didStartElementGSQSS_12namespaceURIGSQSS_13qualifiedNameGSQSS_10attributesGSQCSo12NSDictionary__T_ + 18086
20 SwiftApp 0x0001a335 _TToFC8SwiftApp11AppDelegate6parserfS0_FTGSQCSo11NSXMLParser_15didStartElementGSQSS_12namespaceURIGSQSS_13qualifiedNameGSQSS_10attributesGSQCSo12NSDictionary__T_ + 1221
21 Foundation 0x00d1c00d _startElementNs + 3178
22 libxml2.2.dylib 0x02e8333d xmlParseStartTag2 + 4426
23 libxml2.2.dylib 0x02e860b2 xmlParseTryOrFinish + 3828
24 libxml2.2.dylib 0x02e84fc2 xmlParseChunk + 952
25 Foundation 0x00d19054 -[NSXMLParser parseData:] + 314
26 Foundation 0x00d194f5 -[NSXMLParser parseFromStream] + 276
27 Foundation 0x00d19639 -[NSXMLParser parse] + 33
28 SwiftApp 0x00012b72 _TFC8SwiftApp11AppDelegate11applicationfS0_FTCSo13UIApplication29didFinishLaunchingWithOptionsGSqCSo12NSDictionary__Sb + 1970
29 SwiftApp 0x000133a5 _TToFC8SwiftApp11AppDelegate11applicationfS0_FTCSo13UIApplication29didFinishLaunchingWithOptionsGSqCSo12NSDictionary__Sb + 101
30 UIKit 0x0105bb37 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 291
31 UIKit 0x0105c875 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2920
32 UIKit 0x0105fa33 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1507
33 UIKit 0x01077eb8 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke + 59
34 UIKit 0x0105e77e -[UIApplication workspaceDidEndTransaction:] + 29
35 FrontBoardServices 0x0381bf1f -[FBSWorkspace clientEndTransaction:] + 87
36 FrontBoardServices 0x038234ed __53-[FBSWorkspaceClient _queue_handleTransactionBookEnd]_block_invoke + 49
37 CoreFoundation 0x00788f90 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 16
38 CoreFoundation 0x0077e133 __CFRunLoopDoBlocks + 195
39 CoreFoundation 0x0077d898 __CFRunLoopRun + 936
40 CoreFoundation 0x0077d22b CFRunLoopRunSpecific + 443
41 CoreFoundation 0x0077d05b CFRunLoopRunInMode + 123
42 UIKit 0x0105e095 -[UIApplication _run] + 571
43 UIKit 0x010616e5 UIApplicationMain + 1526
44 SwiftApp 0x0001e471 top_level_code + 97
45 SwiftApp 0x0001eaeb main + 43
46 libdyld.dylib 0x026d0ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
最佳答案
错误在这里:
request.predicate = NSPredicate(format: "id = %@", [nodeId])
因为您将数组传递给 predicateWithFormat
的“可变参数列表”形式。这两个版本都应该有效:
request.predicate = NSPredicate(format: "id = %@", nodeId)
request.predicate = NSPredicate(format: "id = %@", argumentArray: [nodeId])
备注: NSManagedObject
文档声明您“强烈反对”从重写子类中的 description
方法。
关于core-data - CoreData fetchRequest 导致未捕获的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24484263/
Xcode beta 5 推出 @FetchRequest对于 SwiftUI。 我有一个 View ,它有一个 @FetchRequest . NSFetchRequest是在管理器中创建的,该管理
带有实体 Node 的核心数据模型有 name , createdAt , 多对多关系 children和一对一的关系parent (都是可选的)。使用 CodeGen 类定义。 使用 @FetchR
我试图将我的@fetchrequest属性移到辅助类,而不是View,但是每次尝试这样做时,都会收到一条错误的指令错误。 谁能帮我? 这是我的代码的示例: ViewModel: class ViewM
我的 SwiftUI 项目中有以下代码 @FetchRequest private var step: FetchedResults private var processID: UUID priva
我有一个使用 @FetchRequest 显示来自 CoreData 的对象的列表,我想为用户提供一个栏按钮,单击该按钮将过滤显示的列表。如何更改 @FetchRequest 谓词并动态重新运行它以使
我的 SwiftUI 项目中有以下代码 @FetchRequest private var step: FetchedResults private var processID: UUID priva
当我向 CoreData 的一个实体插入数据时,所有行均已成功插入(已保存)。 但是当我尝试使用 FetchRequest 获取数据时,即使插入的行数为 3 或 4 或任何值(超过 1),也只会收到一
更新以下问题:我们能够通过父子关系使用父实体获取请求来查询子实体。示例查询如下: NSPredicate *myPredicate = [NSPredicate predicateWithForm
我正在尝试从我的数据库中获取请求。但我的回应为零。获取是可以的,因为当我使用这种方法时,我得到“有时”值。 (我知道我在数据库中有数据)。我认为这在某种程度上与线程问题有关,或者因为我正在使用多上下文
如何按土耳其语对 fetchResult 进行排序,土耳其语字符在结果末尾排序。 let managedObjectContext = (UIApplication.shared.delegate a
我有一个扩展 NSManagedObject 的静态函数得到这样的对象...... NSManagedObject.get(type: MYUser.self, with: ("id", "SomeU
使用方法 @FetchRequest为了检索单个对象而不是 FetchedResults ?在我看来,我只需要一个对象。是否有另一种方法来执行查询并根据唯一的属性值(例如 ID)获取单个对象? str
我有一组数据,其中一个属性(固件)是一对多关系。 如果我想获取固件 id 为 1 的任何记录,我可以使用创建谓词 @"(ANY Firmware.FID==1)" 然后我有另一组条件,可以使用进一步细
在我的应用程序中,我有两个 CoreData 实体,它们的关系是一对多的:人物 -> 主题 我正在使用列表呈现人们的名字 struct PeopleListView: View { @Fetc
我有 2 个实体: 出席: import Foundation import CoreData extension Attendance { @NSManaged var date: NSDa
更新说明:我正在使用 Big Nerd Ranch CoreDataStack如果你们想知道的话。 我已经为这个具体问题苦苦挣扎了一段时间了。基本上我试图从 CNContactStore 获取联系人并
我正在尝试找到一种方法来预测给定日期第一次发生的事件。假设一个事件在一天中发生多次(范围 1-16),我只希望它返回第一次出现的事件,然后在第二天查找下一个第一次出现的事件。 最佳答案 您无法通过一个
所以我有两个实体。列表和评论。一个列表可以有多个关联的评论。 extension Listing { @NSManaged var listingTitle: String? @NSM
我在尝试过滤 fetchRequest 时脑子崩溃了。 我能够获取实体每条记录的完整详细信息,但我只想要当前 indexPath 处记录的详细信息。 这是我的代码目前所在的位置: -(void) fe
我正在尝试获取按其属性之一(单词)过滤的实体列表,为此我使用了 fetchedResultsController,一切看起来都正常。该列表已加载并显示在我的 tableView 上,我什至可以对列表进
我是一名优秀的程序员,十分优秀!