- Code: Select all
@interface SomeClass : NSObject
@property (nonatomic, weak) id<SomeDelegateProtocol> delegate;
@end
Assigning a mock to that delegate property will see the mock immediately nilled, even though it's held elsewhere with a strong reference.
- Code: Select all
- (void)testSomeMethod {
SomeClass *object = [[SomeClass alloc] init];
id delegate = [OCMockObject mockForProtocol:@protocol(SomeDelegateProtocol)];
object.delegate = delegate;
STAssertNotNil(delegate, @"should have created delegate");
STAssertNotNil(object.delegate, @"should have assigned delegate");
}
The second assertion fails. The first assertion is there to illustrate that the actual object is not deallocated, just the weak reference is lost. I don't understand why the reference is nilled, since the object is not deallocated.
Github repo demonstrating the issue: https://github.com/adamstegman/ARCMock