Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Declaration in C:
Code:
YourClassName * arrayName[ 52 ];
Store an object into the array:
Code:
arrayName[ someIndex ] = [[YourClassName alloc] init];
Refer to an indexed object:
Code:
someThing = arrayName[ someIndex ];

If you really meant an NSArray of objects, or NSMutableArray of objects, then make an instance of the array class in the usual way, then fill it in the usual way, and access its members in the usual way.

If neither of the above answers your question, then you need to explain your question more clearly.
 
Declaration in C:
Code:
YourClassName * arrayName[ 52 ];
Store an object into the array:
Code:
arrayName[ someIndex ] = [[YourClassName alloc] init];
Refer to an indexed object:
Code:
someThing = arrayName[ someIndex ];

If you really meant an NSArray of objects, or NSMutableArray of objects, then make an instance of the array class in the usual way, then fill it in the usual way, and access its members in the usual way.

If neither of the above answers your question, then you need to explain your question more clearly.

I was in a bit of a rush, so sorry for not clarifying my question.

I'm using an NSMutableArray, so here's my code:

Code:
//Declaration:
NSMutableArray *arrayOfObjects = [[NSMutableArray alloc]init];

//Assigning:

for (int i = 0; i < 52; i++) {
        
        [self.arrayOfObjects addObject:[[MyClass alloc]init]];
        
 }

//Accessing:
[[self.arrayOfObjects objectAtIndex:index]property] = ... //Code to set the property to

So that's what I tried, but I'm getting 2 errors:
1. Multiple methods named "property" found wit mismatched result, parameter type, or attributes

2. Assigning to 'readonly' return result of Objective-C not allowed.

I can try your C method suggestion, but please also clarify what I'm doing wrong in the method above. Thank you :eek:

Thank you very much for your time. And sorry for not clarifying well enough.
 
That is definitely not how property setters are used in Obj-C.

You have two possible syntaxes to choose from:

Code:
obj.property = value;

or

Code:
[obj setProperty:value];

Where obj would have [self.arrayOfObjects objectAtIndex:index] substituted in your case, regardless of which syntax you choose to go with.
 
That is definitely not how property setters are used in Obj-C.

You have two possible syntaxes to choose from:

Code:
obj.property = value;

or

Code:
[obj setProperty:value];

Where obj would have [self.arrayOfObjects objectAtIndex:index] substituted in your case, regardless of which syntax you choose to go with.

Dang. I knew I made a noob mistake somewhere in the getters and setters– thank you for your time!
 
Declaration in C:
Code:
YourClassName * arrayName[ 52 ];
Store an object into the array:
Code:
arrayName[ someIndex ] = [[YourClassName alloc] init];
Refer to an indexed object:
Code:
someThing = arrayName[ someIndex ];

If you really meant an NSArray of objects, or NSMutableArray of objects, then make an instance of the array class in the usual way, then fill it in the usual way, and access its members in the usual way.

If neither of the above answers your question, then you need to explain your question more clearly.


Actually ARC doesn't support memory management of C arrays that contain objects. If you use the syntax you proposed it will complain, and those objects would be deallocated as soon as the local variable that was used to create them went away.

You'd have to use a __bridge_retained cast as you stored the objects in the C array, and then a __bridge_transfer when you extracted them from the C array.

With ARC, memory management of C data structures (like C arrays) that contain NSObjects becomes a pain.

Much better to use NSArrays, since they take ownership of the objects and release them when you remove them from the array.

I will use C arrays of pointers to malloc'ed data sometimes, and then the memory management is totally up to me.
 
Actually ARC doesn't support memory management of C arrays that contain objects. If you use the syntax you proposed it will complain, and those objects would be deallocated as soon as the local variable that was used to create them went away.

You'd have to use a __bridge_retained cast as you stored the objects in the C array, and then a __bridge_transfer when you extracted them from the C array.

With ARC, memory management of C data structures (like C arrays) that contain NSObjects becomes a pain.

Much better to use NSArrays, since they take ownership of the objects and release them when you remove them from the array.

I will use C arrays of pointers to malloc'ed data sometimes, and then the memory management is totally up to me.

Thank you very much. I'll just use an NSArray to make things simpler.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.