MagicalRecord.saveWithBlock({ context in
if let items = dictionary["items"] as? Array<NSDictionary> {
for itemInfo in items {
DBItem.findOrUpdateItemWithDictionary(itemInfo, inContext: context)
}
}
//is called
if let sets = dictionary["item_sets"] as? Array<NSDictionary> {
for setInfo in sets {
DBSet.findOrUpdateSetWithDictionary(setInfo, inContext: context)
}
}
}, completion: { finished, error in
completionBlock(error) //is not called
})
这是我设置核心数据堆栈的方式:
MagicalRecord.setupCoreDataStackWithInMemoryStore()
Best Answer-推荐答案 strong>
saveWithBlock: 方法是异步执行的。尽管我不知道您的测试代码如何,但是测试可能在调用完成块之前完成了。
https://github.com/magicalpanda/MagicalRecord/blob/c7b14f658b4fca32f8d33f8f76160203053ce4b9/MagicalRecord/Core/MagicalRecord%2BActions.m#L14-L35
您可以尝试将saveWithBlock: 方法更改为saveWithBlockAndWait: 吗?它是同步执行的。还是等待使用XCTestExpectation 执行异步调用?
关于ios - 未在测试目标下调用MagicalRecord完成 block ,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/31872105/
|