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

  • Home
  • SEARCH
  • 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 1808116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:13:16+00:00 2026-05-17T06:13:16+00:00

One of the things I’ve been struggling with, whilst breaking into Objective-C programming, is

  • 0

One of the things I’ve been struggling with, whilst breaking into Objective-C programming, is understanding how to manipulate properties. I’m perhaps out of my comfort zone using a proper coding language as opposed to scripting languages that I’m used to, so the declaring things in header files and implementation files is confusing me somewhat.

Let’s say I have a String. I wish to add some text into that string. What do I declare in the header file and what do I do in the implementation file to allow this to work properly, and what are @property and @synthesize?

  • 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-17T06:13:17+00:00Added an answer on May 17, 2026 at 6:13 am

    In the bad old days before Objective-C 2.0, it was common to write getters and setters for your instance variables e.g.

    @interface Foo : NSObject
    {
    @private 
        id foo;
    }
    -(void) setFoo: (id) newFoo;
    -(id) foo;
    @end
    
    @implementation Foo
    
    // need dealloc to release foo too.
    
    -(void) setFoo: (id) newFoo
    {
        [newFoo retain];
        [foo release];
        foo = newFoo;
    }
    
    -(id) foo
    {
       return foo;
    }
    @end
    

    And that’s just in the single threaded environment. There was even more stuff needed for multithreaded apps.

    Properties provide a neat shorthand for the above. The @property replaces both of the declarations in the interface as well as giving the caller better hints about the semantics of the getter and setter. It also allows you to @synthesize the accessors so the compiler will generate the code for them automatically (you don’t have to @synthesize them, you can provide your own implementations if you want). All of the above can be replaced by

     @interface Foo : NSObject
    {
    @private 
        id foo;
    }
    @property (nonatomic, retain) id foo;
    @end
    
    @implementation Foo
    
    // need dealloc to release foo too.
    
    @synthesize foo; 
    @end
    

    That saves quite a lot of typing but also you can see from the interface that setFoo: will retain its new value and that the property is not safe to use (to set or get) in a multithreaded environment (without some other locking mechanism).

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

Sidebar

Related Questions

One of the things that has been talked about a few times on the
What are all the things one needs to be careful about when coding in
I've heard that there are some things one cannot do as a computer programmer,
There seem to be a number of weird things one could do if one
One of the things that get me thoroughly confused is the use of session.Flush
One of the things I miss the most in ActionScript is the lack of
One of the things that always bugs me about using Readers and Streams in
One of the things that the Microsoft documentation says about enabling reliable sessions is
One of the things that seems to be necessary with use of STL is
One of the things I like about Java servlets is the use of unobtrusive

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.