2

I just upgraded to Xcode version 4.3.2 (4E2002). I'm converting a mock class from manual memory management to ARC.

The code looks like this:

@implementation OCProtocolMockObject

- (id)initWithProtocol:(Protocol *)aProtocol
{
    [super init];
    mockedProtocol = aProtocol;
    return self;
}

- (NSString *)description
{
    return [NSString stringWithFormat:@"OCMockObject[%s]", [mockedProtocol name]];
}

The @interface looks like this:

@interface OCProtocolMockObject : OCMockObject 
{
    Protocol    *mockedProtocol;
}

The compiler complains that:

 "Receiver type 'Protocol' for instance message is a forward declaration".

"mockedProtocol" is highlighted in the description method.

I've run into this problem before. In ARC mode, usually its because the compiler is stricter about forward references, and you just need to include the appropriate header file.

However, the only "Protocol.h" I can find is

#import <objc/Protocol.h>

Importing this does nothing. Also, adding the import to OCProtocolMockObject.h does nothing. Is there some other Protocol.h I'm not aware of?

adonoho
  • 4,339
  • 1
  • 18
  • 22
nont
  • 9,322
  • 7
  • 62
  • 82
  • What does the `@interface` for `OCProtocolMockObject` look like? – Adam Rosenfield Apr 02 '12 at 20:46
  • nothing special. Updated to include it. (OCMockObject also uses Protocol, but including it there also does nothing) – nont Apr 02 '12 at 20:55
  • It seems that Protocol is only forward declared these days. This caused different problems before, please see the comments on https://github.com/erikdoe/ocmock/pull/7 I have to upgrade to the new version on my Lion machine to double check. – Erik Doernenburg Apr 05 '12 at 10:34
  • Ok, I've upgraded and I can still use OCMock in a project compiled with ARC (see https://github.com/erikdoe/ocmock/tree/master/Examples/ArcExample). Somehow I think you're trying to compile OCMock itself with ARC enabled. I looked into this myself and there are several issues, not only the declaration of Protocol. – Erik Doernenburg Apr 06 '12 at 18:43
  • Thanks Erik. You're correct - I tried to run the ARC conversion tool on the whole project, which contained the OCMock classes. I'm going to just use -fno-objc-arc on the OCMock classes, or compile them separately. – nont Apr 06 '12 at 23:57

1 Answers1

1

Resolved by compiling OCMock without ARC. (use the -fno-objc-arc flag on each of the OCMock source files)

nont
  • 9,322
  • 7
  • 62
  • 82
Ben Flynn
  • 18,524
  • 20
  • 97
  • 142