mardi 26 janvier 2016

Strange retain cycle warning in unit tests in Xcode

I have a service that I'm currently writing a unit test for. The code works as expected, but I'm getting a strange retain cycle warning.

[self.myService doSomethingCoolWithCompletionBlock:^(MyResponseObject *obj) {
    XCTAssertNil(obj, @"obj should be nil");
}];

The XCTAssertNil(obj, @"obj should be nil"); line shows a warning in Xcode Capturing 'self' strongly in this block is likely to lead to a retain cycle.

If I change the code to the following, the warning is removed:

__weak MyService *weakService = self.myService;
[weakService doSomethingCoolWithCompletionBlock:^(MyResponseObject *obj) {
    XCTAssertNil(obj, @"obj should be nil");
}];

I am using self.someService in other unit tests, and never had this issue. Anyone experienced this before?

Aucun commentaire:

Enregistrer un commentaire