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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:08:26+00:00 2026-06-06T19:08:26+00:00

What is technically wrong with the following: @property(nonatomic, assign) NSUInteger timestamp; @property(nonatomic, readonly, getter

  • 0

What is technically wrong with the following:

@property(nonatomic, assign) NSUInteger timestamp;
@property(nonatomic, readonly, getter = timestamp) NSUInteger startTime;
@property(nonatomic, assign) NSUInteger endTime;

I am sure I can find a better way to organise this, but this is what I ended up with at one point in my project and I noticed that accessing the startTime property always returned 0, even when the timestamp property was set to a correct timestamp.

It seems having set the getter of startTime to an existing property (timestamp), it is not forwarding the value of timestamp when I do:

event.startTime => 0
event.timestamp => 1340920893

All these are timestamps by the way.

Just a reminder, I know the above should have happened in my project but I don’t understand why accessing startTime doesn’t forward onto timestamp property.

UPDATE

In my implementation I am synthesising all of these properties:

@synthesize timestamp, endTime, startTime;

Please check an example object to use that demonstrates this at my gist on GitHub: https://gist.github.com/3013951

  • 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-06T19:08:27+00:00Added an answer on June 6, 2026 at 7:08 pm

    In your description method, you aren’t using the property, you’re accessing the ivar.

    -(NSString*) description
    {
        return [NSString stringWithFormat:@"Event< timestamp:%d, start:%d >", 
                 timestamp, 
                 startTime]; // <-- This is accessing the instance variable, not the property.
    }
    

    This will work for you:

    -(NSString*) description
    {
        return [NSString stringWithFormat:@"Event< timestamp:%d, start:%d >", 
                 timestamp, 
                 self.startTime]; // <-- This is using the property accessor.
    }
    

    The property-vs-ivar thing messes people up all the time, so excuse me while I ramble on about it for a minute. 🙂 If you already know all of this, skip ahead.

    When you create and synthesize a property, as you did above, two things happen:

    1. an ivar is created of the proper type.
    2. a getter function is created, which returns that ivar.

    The important part about point 2 is that, by default, the ivar and the getter function (and therefore, the property) have the same names.

    So this:

    @interface Event
    @property(nonatomic, assign) NSUInteger timestamp;
    @property(nonatomic, readonly, getter = timestamp) NSUInteger startTime;
    @end
    
    @implementation Event
    @synthesize timestamp, startTime;
    @end
    

    …turns into this:

    @interface Event {
        NSUInteger timestamp;
        NSUInteger startTime;
    }
    @end
    
    @implementation Event
    - (NSUInteger) timestamp {
        return timestamp
    }
    
    - (void) setTimestamp:(NSUInteger) ts {
        timestamp = ts;
    }
    
    - (NSUInteger) startTime {
        return [self timestamp];
    }
    @end
    

    How dot syntax works is that this:

    NSUInteger foo = myEvent.startTime;
    

    really does

    NSUInteger foo = [myEvent startTime];
    

    All of that to say that when you access an ivar, you’re… well, accessing an ivar. When you use a property, you’re calling a function which returns a value. More importantly, it’s exceedingly easy to do one thing when you meant the other, because the syntax is so very similar. It’s for this reason that many people routinely synthesize their ivars with leading underscores, so that it’s harder to mess up.

    @property(nonatomic, assign) NSUInteger timestamp;
    @property(nonatomic, readonly, getter = timestamp) NSUInteger startTime;
    
    @synthesize timestamp = _timestamp;
    @synthesize startTime = _startTime;
    
    NSLog( @"startTime = %d", _startTime );  // OK, accessing the ivar.
    NSLog( @"startTime = %d", self.startTime );  // OK, using the property.
    NSLog( @"startTime = %d", startTime );  // NO, that'll cause a compile error, and 
                                            // you'll say "whoops", and then change it 
                                            // to one of the above, thereby avoiding
                                            // potentially hours of head-scratching.  :)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So technically a boolean is True (1) or False(0)...how can I use a boolean
I'm aware technically you can't do this as inline always takes president. Inline element
I have the following entities: Books, Authors, and Stores. Each of them can have
Note: I know this is wrong , but this is a technical requirement by
Technically it should iterate from 0 to rangeLength outputting the user name of the
I know that technically all three ways below are valid, but is there any
I'm technically savvy but don't have extensive experience with servers/daemons (I'm a Windows guy,
I don't think this is technically a macro but I don't know what else
concerning Gmail labels - what are they technically speaking. I mean through imap connection
The text in the book i am reading states in summary Technically, constructors cannot

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.