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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:01:49+00:00 2026-05-23T19:01:49+00:00

if we use a property without the retain, what does it change? i have

  • 0

if we use a property without the “retain”, what does it change? i have this example :

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;  
- (id)initWithCoordinate:(CLLocationCoordinate2D) coordinate;

in the .m :

-(id)initWithCoordinate:(CLLocationCoordinate2D)coord{  
    coordinate = coord;  
    return self;  
}

the “retain” is normally used for the setter, isn’t it? so here, we use the setter, in initWith…, but we don’t use “retain”… any idea?

Thanks

  • 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-23T19:01:51+00:00Added an answer on May 23, 2026 at 7:01 pm

    CLLocationCoordinate2D is not an Objective C object, so attempting to send retain and release to it doesn’t make sense.

     @property (nonatomic, readonly) CLLocationCoordinate2D coordinate; 
    

    This declares an assign read only property, which is the only correct thing to do for a property with a plain C type. Additionally you have said it is nonatomic which means that there is no code to synchronize the property. Since the property is a struct consisting of two 64 bit values, that probably means that you can get an inconsistent result back if you read the property at the same time as some other thread is changing it.

    the “retain” is normally used for the setter, isn’t it? so here, we use the setter, in initWith…

    No, you don’t actually. The line

    coordinate = coord;
    

    actually assigns the instance variable directly. However, this is what you want in this case. If the property was not read/write and was an Objective-C object type, it would still be assigning the instance variable directly. In that case, you’d need one of the following.

    [self setCoordinate: coord];
    

    or

    self.coordinate = coord;
    

    or

    coordinate = [coord retain]; // in init only
    

    By the way, your init is wrong. It should follow the pattern:

    -(id)initWithCoordinate:(CLLocationCoordinate2D)coord{ 
        self = [super init]; // assuming init is the designated initialiser of the super class
        if (self != nil)
        { 
            coordinate = coord;
        }
        return self;  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to use Property Injection in Ninject 2 without using the
I have an NSDate* that I'm storing as a property with the retain keyword:
@interface: UIImageView *myImageView; @property (nonatomic, retain) UIImageView *myImageView; @implementation: @synthesize myImageView; - (void)viewDidLoad {
Good Day. On my AppDelegate.h @property (nonatomic, retain) Config *AppConfig; Within my AppDelegate.m, I
Can I use an .ico in the css cursor property without consequences (i.e full
In my Asp.Net project I wanna use Property Auto-wiring, e.g. for my ILogger. Basically
You can use the Filter property of a BindingSource to do SQL like filtering.
I am trying to use the range property of the jQuery slider so that
In C# I use the Length property embedded to the array I'd like to
i need to use the animate property for a less than usual activity. i

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.