核心数据 NSFetchedResultsController:在设备上调试时出错(无法为谓词生成 SQL)

发布于 2024-11-17 13:36:17 字数 2766 浏览 0 评论 0原文

当我在设备上调试我的应用程序时,我遇到了一个奇怪的异常。在模拟器中调试按预期工作。

  • 我使用核心数据来存储模型中的数据
  • 关系,如下所示:位置<->位置详情->> HappyHour
  • 我使用 NSFetchedResultsController 来填充 UITableView
  • 我对 Objective-C 开发也很陌生,

我需要有一个 SUBQUERY 来获取 HappyHour 实体的属性。

像这样:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(0 != SUBQUERY(details.%K, $hh, ($hh.startTime < %@) AND ($hh.endTime > %@)).@count)", weekdayString, theDate, theDate];

仅在设备上我收到此错误/异常:

* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“无法为谓词生成 SQL (0 != SUBQUERY(details.hh_montag) , $hh, $hh.startTime < CAST(316482000.000000, "NSDate") AND $hh.endTime > CAST(316482000.000000, "NSDate")).@count) (RHS 上的问题)'

0 CoreFoundation 0x32cf964f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x3313cc5d objc_exception_throw + 24
2 CoreData 0x3228a829 -[NSSQLGenerator newSQLStatementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:] + 688
3 CoreData 0x3228a2eb -[NSSQLAdapter _newSelectStatementWithFetchRequest:ignoreInheritance:] + 378
4 CoreData 0x3228a169 -[NSSQLAdapter newSelectStatementWithFetchRequest:] + 16
5 CoreData 0x3228a005 -[NSSQLCore newRowsForFetchPlan:] + 288
6 CoreData 0x322892c5 -[NSSQLCore 对象ForFetchRequest:inContext:] + 420
7 CoreData 0x32288875 -[NSSQLCoreexecuteRequest:withContext:error:] + 304
8 CoreData 0x32287dd5 -[NSPersistentStoreCoordinatorexecuteRequest:withContext:error:] + 896
9 CoreData 0x3228669f - [NSManagedObjectContextexecuteFetchRequest:错误:] + 374
10 CoreData 0x322b9d7f -[NSFetchedResultsController PerformFetch:] + 766
11 HappyHourRadar 0x0003e723 -[ResultViewController viewDidLoad] + 86
...
抛出“NSException”实例后调用终止 收到信号:SIGABRT(已中止)

进程已完成,退出代码为 -1


[ResultViewController viewDidLoad] +86

调用[self fetchedResultsController] PerformFetch:&error]


在控制台中 我还收到此消息:

无法加载符号文件:无法加载符号文件:警告:无法读取 /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.3 的符号(8J2)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib(未找到文件)。


因为我没有找到任何可以帮助我的东西,我想这要么是一些非常奇怪的东西,要么我只是搞砸了一些相当标准的东西,由于我有限的目标c背景,我找不到......

无论如何,我会非常高兴如果有人能给出提示,这样我就可以继续,而不必将整个应用程序模型层重写为肮脏的东西(例如获取所有条目并将它们保存在数组中并处理过滤器函数......类似的东西;))


编辑:

这是模型图。由此自动生成模型文件。

图像链接

生成的 HappyHour 类:

@interface HappyHour :  NSManagedObject  
{
}

@property (nonatomic, retain) NSDate * endTime;
@property (nonatomic, retain) NSDate * startTime;

@end

i have a weird exeption when i debug my app on my device. debugging in simulator works as expected.

  • i use core data for storing my data
  • relationships in model are as follows: Location <-> LocationDetails ->> HappyHour
  • i use NSFetchedResultsController to populate a UITableView
  • i'm also pretty new to objective-c develpoment

i need to have a SUBQUERY to get to the attributes of the HappyHour entity.

Like this:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(0 != SUBQUERY(details.%K, $hh, ($hh.startTime < %@) AND ($hh.endTime > %@)).@count)", weekdayString, theDate, theDate];

ONLY on the DEVICE i get this error/exeption:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to generate SQL for predicate (0 != SUBQUERY(details.hh_montag, $hh, $hh.startTime < CAST(316482000.000000, "NSDate") AND $hh.endTime > CAST(316482000.000000, "NSDate")).@count) (problem on RHS)'

0 CoreFoundation 0x32cf964f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x3313cc5d objc_exception_throw + 24
2 CoreData 0x3228a829 -[NSSQLGenerator newSQLStatementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:] + 688
3 CoreData 0x3228a2eb -[NSSQLAdapter _newSelectStatementWithFetchRequest:ignoreInheritance:] + 378
4 CoreData 0x3228a169 -[NSSQLAdapter newSelectStatementWithFetchRequest:] + 16
5 CoreData 0x3228a005 -[NSSQLCore newRowsForFetchPlan:] + 288
6 CoreData 0x322892c5 -[NSSQLCore objectsForFetchRequest:inContext:] + 420
7 CoreData 0x32288875 -[NSSQLCore executeRequest:withContext:error:] + 304
8 CoreData 0x32287dd5 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 896
9 CoreData 0x3228669f -[NSManagedObjectContext executeFetchRequest:error:] + 374
10 CoreData 0x322b9d7f -[NSFetchedResultsController performFetch:] + 766
11 HappyHourRadar 0x0003e723 -[ResultViewController viewDidLoad] + 86
...
terminate called after throwing an instance of 'NSException'
Signal received: SIGABRT (Aborted)

Process finished with exit code -1


At [ResultViewController viewDidLoad] +86

i call

[self fetchedResultsController] performFetch:&error]


in the console i also get this message:

unable to load symbol file: unable to load symbol file: warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.3 (8J2)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).


As i haven't found anything that could help me, i guess it's either something really weird, or i just messed up something pretty standard, that i can't find because of my limited objective c background...

Anyway, i would be very glad if someone could give a hint, so i can continue without having to rewrite my entire application model layer to something dirty (like fetching all entries and holding them in an array and process filter functions...stuff like that ;) )


edit:

here is the model graph. from this auto-generated the model files.

Link to Image

generated HappyHour class:

@interface HappyHour :  NSManagedObject  
{
}

@property (nonatomic, retain) NSDate * endTime;
@property (nonatomic, retain) NSDate * startTime;

@end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

番薯 2024-11-24 13:36:17

我想通了。希望这能帮助那些像我一样盲目、疲倦或其他什么的人。 ;)

这些粗体标记的段落显然不匹配:

  • 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“无法为谓词生成 SQL (0 != SUBQUERY(details.hh_montag, $hh , $hh.startTime < CAST(316482000.000000, "NSDate") AND $hh.endTime > CAST(316482000.000000, "NSDate")).@count) (RHS 上的问题)'

@class 位置;

@interface 位置详细信息:
NSManagedObject { }

@property(非原子,保留)NSString * 电话;

...

@property(非原子,保留)NSSet * hh_monday;

...

@结束

最终的解决方案是:

NSTimeInterval secondsPerDay = 7 * 60 * 60;
NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"EEEE"];

SOLUTION >> [f setLocale: [[[NSLocale alloc] initWithLocaleIdentifier:@"en_UK"] autorelease]];

NSString *weekdayString = [NSString stringWithFormat:@"hh_%@", [[f stringFromDate:[NSDate dateWithTimeIntervalSinceNow:-secondsPerDay]] lowercaseString]];

黄金法则:

始终记住,设备在不同的位置/语言中会有不同的工作方式。

因此,也许可以避免从依赖于位置/语言的类(如 NSDate(Formatter))生成键选择器(?)。
或者确保这些类对于每种情况都返回相同的值。 (希望我已经用这个解决方案解决了一些问题......如果我弄错了,请纠正我。)

i figured it out. Hopefully this will help someone, who is as blind, tired or whatever as myself. ;)

These bold marked passages clearly don't match:

  • Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to generate SQL for predicate (0 != SUBQUERY(details.hh_montag, $hh, $hh.startTime < CAST(316482000.000000, "NSDate") AND $hh.endTime > CAST(316482000.000000, "NSDate")).@count) (problem on RHS)'

and

@class Location;

@interface LocationDetails :
NSManagedObject { }

@property (nonatomic, retain) NSString * phone;

...

@property (nonatomic, retain) NSSet * hh_monday;

...

@end

The final solution was:

NSTimeInterval secondsPerDay = 7 * 60 * 60;
NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"EEEE"];

SOLUTION >> [f setLocale: [[[NSLocale alloc] initWithLocaleIdentifier:@"en_UK"] autorelease]];

NSString *weekdayString = [NSString stringWithFormat:@"hh_%@", [[f stringFromDate:[NSDate dateWithTimeIntervalSinceNow:-secondsPerDay]] lowercaseString]];

Golden Rule:

Always keep in mind, that a device will work differently in a different location/language.

So, maybe avoid producing key selectors(?) from location/language-dependent classes like NSDate(Formatter).
Or make sure, that these classes return the same values for every case. (Hopefully something I have taken care of with this solution...correct me if I got that wrong.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文