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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:45:34+00:00 2026-05-28T05:45:34+00:00

Im a C# developer whom is new to Objective C and this migration has

  • 0

Im a C# developer whom is new to Objective C and this migration has not been easy due to the difference between the two languages.

What im try do is to create a class that has properties similar to as you do in C#.
If for ex have a C# class which looks like:

public class X
{
  private int _d, _y;

  public int D { get {return _d; } set{ _d= value;}}
  public int Y { get{ return _y;} set {_y = value;}}
}

Who does one write this in objective C?

I have tried but been unable to do this.
My objective C class for the moment looks like this:

@interface X : NSObject
{
   @private
     int _d ,_y;
}

@property (nonatomic, readwrite, retain) int d;
@property (nonatomic, readwrite, retain) int y;

@end

@implementation X

@synthesize d = _d;
@synthesize y = _y;

-(void)dealloc
{
  [d release];
  [y release];
  [super dealloc];
}

@end

Thank you in advance.

  • 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-28T05:45:34+00:00Added an answer on May 28, 2026 at 5:45 am

    The following code is like your class in C#

    @interface X : NSObject
    {
       @private
       int _d, _y;
    }
    
    @property (nonatomic, assign) int d;
    @property (nonatomic, assign) int y;
    
    @end
    
    @implementation X
    
    @synthesize d = _d;
    @synthesize y = _y;
    
    - (void) dealloc
    {
       [super dealloc];
    }
    
    @end
    

    Some notes

    When you use primitive type like int, your cannot retain it. You can only use assign policy (the default one). Retain policy is used only with objects. Also readwrite policy is set by default. If you want to have only a getter for that variable use readonly (instead of readwrite).

    For further information see Property Declaration Attributes section in properties reference.

    Edit

    For NSString you can do the follow:

     //.h
    @interface X : NSObject    
    {
        @private
        NSString* _myString;
    }
    
    @property (nonatomic, copy) NSString* myString;
    
    @end
    
    //.m
    @implementation X
    
    @synthesize myString = _myString;
    
    - (void) dealloc
    {
       [_myString release];
       _myString = nil;
    
       [super dealloc];
    }        
    
    @end
    

    Since NSString is an object (note the *) you have to release that object in dealloc method.

    You should use copy policy for NSString. This is explained in the following stackoverflow topic.

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

Sidebar

Related Questions

From a desktop application developer point of view, is there any difference between developing
I'm working within the parameters of an un-reachable developer, whom has created an html
http://developer.yahoo.com/javascript/howto-proxy.html Are there disadvantages to this technique? The advantage is obvious, that you can
Having been a PHP developer on LAMP servers for quite a while, is there
A developer of ours tends not to specify messages when committing his code, I
The developer documentation has seemed to have failed me here. I can create a
Developer tools and software typically do not provide solution suggestions in error messages .
Developer signed an app with his personal keystore but it should have been the
http://developer.android.com/guide/topics/manifest/service-element.html#proc What are the differences? If the name assigned to this attribute begins with
A developer has left, and his workstation is now formatted. TFS thinks he still

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.