autorelease object not confirming protocol does not give any warning
- by Sahil Wasan
I have a class "ABC" and its method which returns non autoreleases object of that class.
@interface ABC:NSObject
+(ABC *)aClassMethodReturnsObjectWhichNotAutoreleased;
@end
@implementation ABC
+(ABC *)aClassMethodReturnsObjectWhichNotAutoreleased{
ABC *a = [[ABC alloc]init];
return a;
}
@end
If I have a protocol Foo.
@Protocol Foo
@required
-(void)abc;
@end
My ABC class is "not" confirming Foo protocols.
1st call
id<Foo> obj = [ABC aClassMethodReturnsObjectWhichNotAutoreleased]; //show warning
It shows warning "Non Compatible pointers.." thats good.Abc did not confirm protocol Foo
BUT
2nd call
id<Foo> obj = [NSArray arrayWithObjects:@"abc",@"def",nil]; // It will "not" show warning as it will return autorelease object.NSArray don't confirm protocol Foo
In first call compiler gives warning and in second call compiler is not giving any warning.I think that is because i am not returning autorelease object.
Why is compiler not giving warning in 2nd call as NSArray is also not confirming FOO
Thanks in advance