Gcc - Warning passing argument from distinct Objective-C type

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I am currently trying to compile OCMock with GCC4.2 (original: 4.0) and start getting the following warning:

warning: passing argument 1 of partialMockForObject: from distinct Objective-C type

the calling method is:

- (void)forwardInvocationForRealObject:(NSInvocation *)anInvocation
{
    // in here "self" is a reference to the real object, not the mock
    OCPartialMockObject *mock = [OCPartialMockObject partialMockForObject:(id)self];
    // ...
}

and the called method is:

+ (id)partialMockForObject:(NSObject *)anObject;

prefixing the argument with a cast to id fixes the problem. I thought all objects were subclass of NSObject and though the cast would be made implicit (super class substitution: a super class can always be replaced by any child class of it)

Answers

All objects are not necessarily descended from NSObject. Most Cocoa classes are (NSProxy is the only exception that occurs off the top of my head), but if you don t declare a class as being descended from NSObject, it won t be. Could it be that you forgot that in the declaration of wherever this occurs?

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/1515984/warning-passing-argument-from-distinct-objective-c-type

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils