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

adamstegman/ARCMock

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

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