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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:47:14+00:00 2026-06-18T16:47:14+00:00

I have a Singleton class called Constants and I need to set some app

  • 0

I have a Singleton class called Constants and I need to set some app wide constants in there. Id like these constants to be readonly. So I did the following in the Constants.h file

 @interface Constants : NSObject
 {

 }

 @property (nonatomic, readonly)double U_LAT;
 @property (nonatomic, readonly)double U_LNG;

Then in my .m fileI got this method

 -(id)init
 {
     self = [super init];

     self.U_LAT = 49.2765;
     self.U_LNG = -123.2177;

     return self;
 }

I get this error from this code:

 Assignment to readonly property

Can I not initialize my readonly variable in the init method? If not how do I initialize them?

  • 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-18T16:47:15+00:00Added an answer on June 18, 2026 at 4:47 pm

    self.propertyName = val; is the same as [self setPropertyName:val]; — it requires a setter method to exist. Read-only properties don’t have setter methods.

    You can set the ivar which backs the property directly, however:

    -(id)init
     {
         self = [super init];
    
         _U_LAT = 49.2765;
         _U_LNG = -123.2177;
    
         return self;
     }
    

    The ivar’s name will be the property name prefixed with an underscore if you are allowing the properties to be synthesized automatically. If you have an explicit @synthesize propName;, the ivar will have the same name. You can also create a variable with any name you like, again using a synthesize statement: @synthesize cat = dog;

    It’s also possible for the property to be read-only publicly, but be writeable by the class; this involves either declaring a setter method in a class extension or redeclaring the property in the extension.

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

Sidebar

Related Questions

I have a singleton class where I set up a NSMutableDictionary called completedLevels .
My app has a singleton class called CycleManager. I have created a sealed class
I have a C++ singleton factory-like class called MemMgr which is in charge of
I have a singleton class which is being used throughout the app. I am
The goal is to have a singleton data controller class called FetchData.h/.m that pulls
I have a singleton class called SingletonController1. This SingletonController1 instantiates a bunch of others
I have a singleton class that registers a preference change listener like: PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()) .registerOnSharedPreferenceChangeListener(
I have an abstract base class called Curve . There are three classes that
I have a method in a singleton class that need to use the .NET
I have a singleton class called Manager that holds a list of object instances:

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.