API violation - multiple calls made to -[XCTestExpectation fulfill]

♀尐吖头ヾ 提交于 2019-12-05 02:32:21
Cirec Beback

I suggest best handing of a multiple occurring expectation is to set your expectation variable to nil after the fulfill. Then, subsequent calls will be ignored.

Objective-C:

// Fulfill and remove. Subsequent messages to nil are ignored.
[multiEx fulfill];
multiEx = nil;`

Swift:

// Fulfill and remove. Optional chaining ends execution on nil.
var multiEx:XCTestExpectation? = expectationWithDescription("multiEx")
...
multiEx?.fulfill() 
multiEx = nil
mehmetg

I was having the same issue (in Objective-C); I added a check for null ptr before fulfill and it seems to work stably for me.

I had been struggling with this for a while, and the most voted answer didn't work for me. The main difference was that the async response was coming through a delegate, not a closure.

What did work for me was to set my delegate to nil after the first call to 'fulfill'.

Hope it helps someone.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!