Search code examples
objective-cinterfaceaccessorcustom-data-type

Why does the compiler insists a method returns a "void" when the header file claims the method returns a float?


The class interface for an object claims that an accessor to one of its instance variables returns data of type "float." However, when I attempt to compile a script to access this variable, the compiler throws the following error: "Initializing 'float' with an expression of incompatible type 'void.'" The implementation code is proprietary and hidden from me. The last piece of data is that, when stepping through the debugger, the debugger is able to access the method and insists the returned value is of type "float!"

Is it possible for a method to return a different data type than what is described in the interface? How can I find out what this method really returns? Any suggestions on why the compiler, the debugger, and the header file seem to disagree?

In the header file for the object, you can see the that the interface declares that the accessor returns "float" :

@interface SBPulseTag : SBTag {
@private
    float start,end;
    enum PulseTypeEnum pulseType;
}
- (float)start;
- (float)end;
- (void)setStart:(float)val;
- (void)setEnd:(float)val;
@end

In my own code, I have a method that enumerates through an NSArray of 'PulseTag's, like so.

 -(WaveformSegment *) WaveformSegmentTest:(int)myInput {

// <... Some overlying code...>

SBPulseTag *tag;  // Declare an object to receive each object in the array

while(tag = [enumerator nextObject]) {  // Loop through the array
    int tmp = [tag start];  // Initializing 'float' with an expression of incompatible type 'void.'
    }

Lastly, the XCode debugger can clearly access [tag start] and reads it as a float. Here is a snapshot of the debugger output in XCode:

Debugger clearly can read SBPulseTag.start as a 'float'

Any ideas? I'm flummoxed.


Solution

  • You have almost certainly failed to import the header file for SBPulseTag into this .m file.

    Without being able to see the header, ObjC assumes that this method returns void (since there are other selectors called -start that return void; this method should not have been called start, but you have no control over that). I'm suspecting that somewhere you've included @class SBPulseTag, so it knows the class exists, but not its interface.

    Make sure to check for any other warnings. It's possible you have other collisions that the compiler is warning you about.