Obj-C Assignment Warning with Init Method

I have an init method defined as:

- (id)initWithX:(float)inX AndY:(float)inY
{
    if (self = [super init])
    {
        [self setX:inX andY:inY];
    }

    return self;    
}

When I use this method as follows:

MyObject* myObject = [[MyObject alloc] initWithX:0.0 AndY:0.0];

I get a warning: "warning: initialization from a separate Objective-C type"

But interestingly, if I changed “AndY:” to “andY:” in the method signature, the warning disappears.

Why is this happening? Of course, naming my method should not affect its return type?


After a little research, changing the method name, use the lowercase "andY" so that the warning does not disappear. I cleared all the goals and rebuilt, and the warning did not appear. But he returned after another recompilation. Odd

+3
source share
5 answers

, , - , , .

cocoa , , , Toon Van Acker .

"andY:", "y:", , , .

, . , , ...

+1

, .

. , (, -initWi: andY: @interface, -initWi: AndY: @implementation) . , Cocoa , .

+4

"" .h ?

+2

, , , - delcaration ( @interface, , .h) ( @implementation), Objective-C , , id ( ). , AndY:, ( ) , id. float, . , , float, .

+2

I suspect that if you incorrectly named the method, you would have received another warning (initWi thanks: AndY: the method was not found).

What is declared in the header file? Method declaration as

- (NSObject *) initWithX: (float) inX AndY: (float) inY;

for example, provide you with this warning.

+1
source

Source: https://habr.com/ru/post/1712793/


All Articles