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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:11:03+00:00 2026-05-21T21:11:03+00:00

Is it possible to somehow create a custom @synthesize to generate custome getter, setters

  • 0

Is it possible to somehow create a custom @synthesize to generate custome getter, setters ??

For example:

@interface
@property (nonatomic, retain) MyObject *object;
@end

@implementation
@lazyInitialize object;
@end

And then somehow define @lazyInitialize to generate a lazy initializer method

//@lazyInitialize

- (id)"property name"
{
   if (!"property name")
   {
      "property name" = [[["property name" class] alloc] init];
   }
   return "property name";
}
  • 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-21T21:11:03+00:00Added an answer on May 21, 2026 at 9:11 pm

    You could try something different, though. I wouldn’t have thought of this more than a couple days ago, but I happened to be reading Cocoa With Love. In the post linked, he discussed how he made a #define macro that would “generate” the entire class for a singleton into wherever you called the macro from. You can download his code for this (may give ideas on your own implementation).

    Perhaps something like (Warning: Untested Code Ahead):

    #define SYNTHESIZE_LAZY_INITIALIZER_FOR_OBJECT(objectName, objectType) \
    \
    - (objectType *)objectName \
    { \
        if(!objectName) \
        { \
              objectName = [[objectType alloc] init]; \
        } \
        return objectName; \
    } \
    \
    - (void)set##objectName:(objectType *)value \
    { \
        [value retain]; \
        [objectName release]; \
        objectName = value; \
    }
    

    would work? I apologize that I don’t have time to properly test it for you, so take that as fair warning that this isn’t a quick copy/paste solution. Sorry about that. Hopefully it is still useful! 😉


    Example Usage

    This should work, again Warning: Untested Code Ahead:

    Header

    // ....
    @interface SomeClass : NSObject {
        NSObject *someObj;
    }
    @end
    

    Implementation

    @implementation SomeClass
    // ....
    SYNTHESIZE_LAZY_INITIALIZER_FOR_OBJECT(someObj, NSObject);
    // ....
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does somebody know if is it possible somehow to create a custom NSAnimationCurve so
i am asking myself if it is possible to somehow create a dynamic gui
Is it possible to create a Custom Control which inherits from System.Web.UI.WebControls.Login and change
Is it somehow possible to create a stored procedure when using SQLite?
Is it possible to somehow create a pow function for measure types? The pow
Is it possible somehow to create in-memory database in SQLite and then destroy it
Is it somehow possible to create mock service in soapUI without having wsdl file?
Is it possible to somehow create a virtual folder with Java, and hook a
Is it possible somehow to create a solution that can google translate a whole
Is it possible somehow to close StreamReader after calling ReadToEnd method in construction like

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.