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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:05:42+00:00 2026-05-12T05:05:42+00:00

I was wondering if there is any sample code out there for objective-C for

  • 0

I was wondering if there is any sample code out there for objective-C for implementing a NSMutableArray of type struct. Inside, I need there to be 2 mutable arrays (via NSMutableArray also) declared in the struct. All the code samples in my book show me how to make an array of defined size via C array syntax (with the brackets), but I don’t know how to get one going with NSMutableArray. Has anyone else done this before? Here’s my code so far…It compiles fine I have defined the size of the arrays (2 and 5 are used in my code below as an example, but I need to set it so I can have them mutable. I can work with simple structs when they just have some of the “easier-to-understand” data types like int, double, short, long, BOOL (you get the idea). When it gets into pointers though, this is where I become lost (I can use pointers fine, but knowing how to put them in a struct is the difficult part). Once the code is working with NSMutableArray’s, would I put “network” in the interface as a pointer to type “Network”? I tried this before, but I got errors. In the end, I basically want to be able to write

network.input[2].list[1].value = 5.0;

on an arbitrarily defined array of type “Network”. Could anyone offer suggestion or links to information about making a NSMutableArray of type “Network” which includes a struct of two NSMutableArray’s? Thanks for any help!

SomeFile.h

#import <Foundation/Foundation.h>

struct lists{
    double value;
};

// supporting structs
struct inputs{
    struct lists list[2];
};

struct Network {
    struct inputs input[5];
    struct lists output[5];
}

@interface SomeFile : NSObject {

}

@end

SomeFile.m

#import "SomeFile.h"
@implementation SomeFile
@end
  • 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-12T05:05:43+00:00Added an answer on May 12, 2026 at 5:05 am

    This is not be a complete answer; I’m not sure what you mean by not knowing how to put pointers in structs. I’m going to proceed by assuming you want to model an network of multiple inputs and outputs with a dynamic number of both.

    You have a few choices here:

    1. Use value objects instead of structs to store your values:

      [[[network inputs] objectAtIndex:2] replaceObjectAtIndex:1 withObject:[NSNumber numberWithDouble:5.0]];
      
    2. Model your Network with an object:

      @interface Network : NSObject {
          // ivars
      }
      
      - (void) setInput:(double)value atIndex:(NSInteger)valueIndex ofInputAtIndex:(NSInteger)inputIndex;
      - (double) outputAtIndex:(NSInteger)index;
      @end
      
    3. Just use structs like you’re already doing; if you need to change the size up-front, use your friend malloc:

      struct Network_value {
        double value;
      }
      
      struct Network {
          struct Network_value **inputs;
          struct Network_value *outputs;
      };
      
      void Network_alloc(Network *n, unsigned inputs, unsigned input_values, unsigned outputs) {
          n->outputs = calloc(sizeof(Network_value), outputs);
          n->inputs = calloc(sizeof(Network_value *), inputs);
          while (inputs --> 0) {
              n->inputs[inputs] = calloc(sizeof(Network_value), input_values);
          }
      }
      
      void Network_free(Network *n, unsigned inputs) {
          free(n->outputs);
          while (inputs --> 0) {
              free(n->inputs[inputs]);
          }
          free(n->inputs);
      }
      
      Network network;
      Network_alloc(&network, 5, 2, 5);
      
      network.inputs[2][1].value = 5.0;
      
      Network_free(&network, 2);
      
    4. Combine ideas 2 and 3 by presenting a Network object but internally store the values with structs. This is probably a good idea if the number of inputs and outputs is very large.

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

Sidebar

Ask A Question

Stats

  • Questions 144k
  • Answers 144k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A call to new B(); resolves in two things: allocating… May 12, 2026 at 8:35 am
  • Editorial Team
    Editorial Team added an answer It is not likely you would want to create a… May 12, 2026 at 8:35 am
  • Editorial Team
    Editorial Team added an answer It's the == operator. The TimeSpan class has an overload… May 12, 2026 at 8:35 am

Related Questions

One of the people who took the time to comment on my other question
My friend was given this free google website optimizer tshirt and came to me
I'm using a web service for passing information from a bunch of old .asp
I hope this is a simple enough question for any SQL people out there...

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.