autorelease object not confirming protocol does not give any warning

Posted by Sahil Wasan on Stack Overflow See other posts from Stack Overflow or by Sahil Wasan
Published on 2012-11-10T16:09:30Z Indexed on 2012/11/10 17:00 UTC
Read the original article Hit count: 214

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c