discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why/how is count method not emitting warning/error on id?


From: Patryk Laurent
Subject: Why/how is count method not emitting warning/error on id?
Date: Sat, 08 Jul 2017 15:04:29 +0000 (GMT)

Hello,

While experimenting with distributed objects, I noticed that the count method can be called on an id but I cannot just call any arbitrary method on id (e.g., a made-up "countx" method).
Why doesn't calling count on an id generate a compiler warning/error-when-using-ARC?  
It seems the count method is accorded some special status compared to an arbitrary method like "countx"... how does this work?

Code example including the somehow-working [id count] (but erroring other cases, as expected) are shown below.

Thank you,
Patryk


#import <Foundation/Foundation.h>

int main() {
    id _one_ = [[NSObject alloc] init];
    NSObject* two = [[NSObject alloc] init];
    [one count];
    [one countx];
    [two count];
    [two countx];
    return 0;
}

When compiled with ARC:


blessed_methods.m:9:10: warning: instance method '-countx' not found (return type defaults to 'id'); did you mean
'-count'? [-Wobjc-method-access]
[one countx];
^~~~~~
count
blessed_methods.m:10:10: warning: 'NSObject' may not respond to 'count'
[two count];
~~~ ^
blessed_methods.m:11:10: warning: instance method '-countx' not found (return type defaults to 'id')
[-Wobjc-method-access]
[two countx];
^~~~~~




reply via email to

[Prev in Thread] Current Thread [Next in Thread]