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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:27:40+00:00 2026-05-17T17:27:40+00:00

There is really something in objc I cannot understand. I know how to make

  • 0

There is really something in objc I cannot understand. I know how to make retainable properties but cannot understand how to make retainable “sub” struc fields which are not “public” properties but only “private” properties (the private properties are only managed by my methods).

Here is my code:

    struct _device_descriptor {
    NSInteger accessoryNumber;                                    // Accessory the device belongs to
    NSInteger slotNumber;                                        // Slot number used for the device
    NSString* slotName;                                            // Slot name
};
typedef struct _device_descriptor device_descriptor_t;

#define NUMBER_MAX_CARD_READERS 10
#define NUMBER_MAX_ACCESSORIES 10
@interface CardDeviceManager : NSObject {
    // Card devices (among accessories)
    NSInteger m_numberOfCardDevices;                                // Number of devices.
    NSMutableArray* m_accessoryList;                                // List of all accessories
@private
    // Accessories
    NSInteger m_numberOfAccessories;                                // Number of accessories
    NSInteger m_numberOfAcceptedAccessories;                        
    device_descriptor_t m_cardDevice[NUMBER_MAX_CARD_READERS];        // Array of card devices.
}

I want the slot name (slotName in the struct) to be retained each time I assign it in my methods, but this is not a property since not visible from outside.

For example, each time I initialize it with another NSString, I do this:

//_tmpName is a NSString
// Warning: slotName must be released later since we retain it.
m_cardDevice[i].slotName = [[NSString stringWithString: _tmpName] retain];

I really feel this is not a “good” (not elegant) way of doing.

I think I should remove the _device_descriptor struct and have something like this:

NSInteger accessoryNumber[NUMBER_MAX_CARD_READERS];                   // Accessory the device belongs to
    NSInteger slotNumber[NUMBER_MAX_CARD_READERS];                    // Slot number used for the device
    NSString* slotName[NUMBER_MAX_CARD_READERS];     

But this is not better since I do not gather common things in a struct…

Is there a smarter way ?

Regards,
Franz

  • 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-17T17:27:41+00:00Added an answer on May 17, 2026 at 5:27 pm

    You’re right; you can’t do this via property syntax. I’d probably write C functions for getting and setting the struct fields, and then just make an arbitrary rule that accessing data from the structs in any way other than the functions is improper.

    For example, I’d have:

    device_descriptor_t* DeviceDescriptorCreate(NSInteger accessoryNumber,
                                                NSInteger slotNumber,
                                                NSString* slotName); //malloc()
    
    void DeviceDescriptorDestroy(device_descriptor_t* device); //free()
    void DeviceDescriptorSetSlotName(device_descriptor_t* device, NSString* slotName); //release old value, set new one
    NSString* DeviceDescriptorGetSlotName(device_descriptor_t* device);
    

    Et cetera.

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

Sidebar

Related Questions

I'm guessing there's something really basic about C# inheritance that I don't understand. Would
Are methods calls really so slow or is there something wrong in my computer?
The default seems to be upper case, but is there really any reason to
In Python there is a really neat function called zip which can be used
Is there really that much of a difference between the performance of Vector and
Is there really not a TSpinEdit control for floats in Delphi? It looks like
When running tests in Ruby's unit::test framework, is there a really easy way to
Update: Now that it's 2016 I'd use PowerShell for this unless there's a really
I really feel that I should learn Lisp and there are plenty of good
There's not a lot to add to the subject really. I am after a

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.