Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8817575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:52:53+00:00 2026-06-14T04:52:53+00:00

I have a class ABC and its method which returns non autoreleases object of

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:52:54+00:00Added an answer on June 14, 2026 at 4:52 am

    In your first example, the return value is a specific type so the compiler can verify the assignment.

    In the second example, the NSArray arrayWithObjects: method has a return type of id. You can assign an object of type id to a variable of any type. The compiler has no way to verify that what you are doing is truly correct or not.

    This issue has nothing to do with autoreleased objects. It’s all about the data types. id is a kind of catch-all type that can be anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have created a ABCFactory class that has a single method creating ABC
So let's assume I have a class named ABC that will have a list
I have a dll called Test.dll in which I have a class called ABC
An abstract base class (ABC) can have data to support the classes that inherit
I have a partial class that requires some mixin for its functionality (I want
I have an inner class (non-static) which is using a reference to an enclosing
I have a text: <font class=myclass>class abc</font> and i have a pattern: class now,
I have following code snippet: class ABC{ public: int a; void print(){cout<<hello<<endl;} }; int
I have a class named as order in package com.abc I have another class
I have a String variable say strHTML = <div class='abc'> This is a test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.