以下代码在iOS 8上使用Xcode 6正常工作,但在iOS 8和iOS 9上使用Xcode 7编译时会在调试中抛出objec_exception_thrown。我正在使用Parse版本1.9.0 for iOS。
[[localQuery findObjectsInBackground] continueWithSuccessBlock:^id(BFTask *task) {
NSArray *results = task.result;
Level *level = [[LevelManager sharedManager] currentLevel];
int numberOfSolvedLevels = (int) [results count];
int levelNumber = (int)level.serialNumber;
int firstLevelInSection = ((levelNumber / LEVELSECTION_SIZE)*10);
int lastLevelInSection = firstLevelInSection + LEVELSECTION_SIZE;
// Get all the levels in the same range from the local query result
NSPredicate *betweenPredicate = [NSPredicate predicateWithFormat:@"estimatedData.level_num BETWEEN {%d,%d}", firstLevelInSection, lastLevelInSection];
// Throws objec_exception_thrown
NSArray *playedLevelsInBetweenRangeArray = [results filteredArrayUsingPredicate:betweenPredicate];
....
return task;
}];
此处抛出异常:
NSArray *playedLevelsInBetweenRangeArray = [results filteredArrayUsingPredicate:betweenPredicate];
在解析线程中抛出异常(Queue:com.parse-sqlitedb.queue(serial))。
任何信息如何解决这个问题?它在调试模式下运行时只会抛出异常。
这是堆栈跟踪:
Thread 16Queue : com.parse.sqlite.db.queue (serial)
#0 0x000000019a277f48 in objc_exception_throw ()
#1 0x0000000185878c1c in -[NSException raise] ()
#2 0x000000018677dd90 in -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] ()
#3 0x00000001866d00cc in -[NSObject(NSKeyValueCoding) valueForKey:] ()
#4 0x00000001866cff68 in -[NSObject(NSKeyValueCoding) valueForKeyPath:] ()
#5 0x0000000186712cec in -[NSFunctionExpression expressionValueWithObject:context:] ()
#6 0x00000001867127d0 in -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] ()
#7 0x0000000186711728 in _filterObjectsUsingPredicate ()
#8 0x0000000186711524 in -[NSArray(NSPredicateSupport) filteredArrayUsingPredicate:] ()
这是我唯一真正的调试信息:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<PFObjectEstimatedData 0x135b57f60> valueForUndefinedKey:]: this class is not key value coding-compliant for the key level_num.'
答案 0 :(得分:1)
由于您的betweenPredicate
无效,引发了异常。您不应该尝试访问estimatedData
,这是PFObject
私有广告。
如果您在results
数组中获得的对象具有level_num
属性,则您的谓词应该只是:
NSPredicate *betweenPredicate = [NSPredicate predicateWithFormat:@"level_num BETWEEN {%d,%d}", firstLevelInSection, lastLevelInSection];