NSManagedObject具有Transformable属性,我用它来存储NSMutableOrderedSet。
此set包含自定义对象(不是NSManagedObject的子类),它们实现NSCoding并覆盖isEqual:和hash方法。
我有一个NSPredicate来检查这个集合是否包含传递的对象。
谓词基本上就是这个:
[NSPredicate predicateWithFormat:@"%@ IN %K", theObjectToCheck, @"propertyNameForTheSet"];
它适用于内存中的数据库,但使用SQL会触发BAD ACCESS错误。
我启用了所有诊断功能。
sql debug类似于:
CoreData: sql: SELECT COUNT( DISTINCT t0.Z_PK) FROM ZIMPLEMENTED_ABSTRACT_ENTITY_NAME t0 WHERE ( NSCoreDataStringSearch( t0.ZPROPERTYNAMEFORTHESET1, ?, 0, 0) AND t0.Z_ENT = ?)
CoreData: details: SQLite bind[0] = theObjectToCheckAsString(not-hash)
CoreData: details: SQLite bind[1] = 6
堆栈跟踪是:
0 ??? 0x00000001eee4d8dc 0x0 + 8302942428,
1 Spatch 0x00000001020d5ee0 main + 0,
2 CoreData 0x000000010386ee26 _NSCoreDataStringSearch + 246,
3 libsqlite3.dylib 0x0000000107337384 sqlite3VdbeExec + 16100,
4 libsqlite3.dylib 0x000000010728e4ff sqlite3_step + 527,
5 CoreData 0x0000000103820070 _execute + 112,
6 CoreData 0x000000010381fd0b -[NSSQLiteConnection execute] + 1835,
7 CoreData 0x0000000103879b18 -[NSSQLChannel selectCountWithFetchRequest:] + 168,
8 CoreData 0x00000001038796b5 -[NSSQLCore countForFetchRequest:inContext:] + 405,
9 CoreData 0x0000000103825f01 -[NSSQLCore executeRequest:withContext:error:] + 513,
10 CoreData 0x00000001038fb4f3 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 3331,
11 CoreData 0x00000001039037ee gutsOfBlockToNSPersistentStoreCoordinatorPerform + 190,
12 libdispatch.dylib 0x00000001056b17f4 _dispatch_client_callout + 8,
13 libdispatch.dylib 0x0000000105698774 _dispatch_barrier_sync_f_invoke + 365,
14 CoreData 0x00000001038f63d5 _perform + 197,
15 CoreData 0x0000000103825ac8 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 504,
16 CoreData 0x0000000103878c80 -[NSManagedObjectContext(_NSInternalAdditions) _countWithNoChangesForRequest:error:] + 288,
17 CoreData 0x000000010387868b -[NSManagedObjectContext countForFetchRequest:error:] + 331,
似乎与http://markmail.org/message/7cuuamyc4gcid5bb#query:+page:1+mid:h2t4o4moib3emltb+state:results有相似之处
可在此处查看示例项目:https://dl.dropboxusercontent.com/u/2935618/CustomObjectsInCoreData.zip
我有什么想法可以深究这个?非常感谢!
答案 0 :(得分:0)
如果这些不是实体并且没有通过核心数据模型中的显式关系连接,那么使用SQL搜索NSPredicate中的对象似乎是不可能的。