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 3878972
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:40:24+00:00 2026-05-19T22:40:24+00:00

I have been following the iPhone development videos on iTunes U and so far

  • 0

I have been following the iPhone development videos on iTunes U and so far so good. I think I understood things well enough.

The thing is that on the examples they provide they never create custom class methods just like those that you use on some Foundation classes (like [NSString string]) so I’m not sure as to how I should go about creating my own class method to return an autoreleased instance of my class.

I do know how to create a retained object using an instance method but I’d rather use a class method because I prefer it, I’m just not sure if this implementation would be the most appropriate to return an autoreleased object:

+ (PhotoViewController*)initWithImageView:(UIImageView*)imageView
{
    PhotoViewController *toreturn = [[PhotoViewController alloc] init];
    toreturn.imageview = imageView;
    [toreturn autorelease];
    return toreturn;
}

Thanks a lot for any help you may provide.

  • 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-05-19T22:40:25+00:00Added an answer on May 19, 2026 at 10:40 pm

    A class method can return either a retained or autoreleased object as you wish, and your code returns an autoreleased object perfectly appropriately.

    However you should probably name your method differently. Since your method begins with init, that implies it is initialising an alloced object (and should therefore be an instance method rather than a class method). I’d suggest naming the method photoViewControllerWithImageView: if it’s going to return an autoreleased object.

    Also, I’d probably write it as return [toreturn autorelease]; but I guess that’s a style preference of mine.

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

Sidebar

Related Questions

I have been following a tutorial on creating an iPhone app with multiple xibs.
Noobie so bear with me. I've have been following the O'Rielyy Learning iPhone Programming
I'm just starting iPhone development (coming fron a .Net world) and have been going
I have been following a HelloWorld tutorial on how to create a basic iphone
I have been following the answer of this question: How to update existing object
I have been following the usage of JavaScript for the past few years, and
I have been following the following post on using multiple ItemTemplates in a ListView
I have been following mozilla developer network's docs and created a transition for my
I have been following a couple of articles regarding RESTful web services with WCF
I have been following the validation for Entry boxes from here . The code

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.