Skip to content
This repository was archived by the owner on Dec 10, 2020. It is now read-only.

adamstegman/ARCMock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ARCMock

iOS has an issue with NSProxy objects under ARC, probably most commonly seen when mocking delegates with OCMock. This project includes an XCode project that can be built and tested to demonstrate the issue.

The Issue

Basically, given a delegate protocol and a class that uses a delegate:

@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.

- (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 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.

Links

About

iOS project illustrating a weak reference issue with OCMock

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published