I have this array Array *array = [@"string1", @"string2", @"string3", @"string4"];
I want to get each string object and assign to dynamically created NSString objects.
Is it possible?
I have this array Array *array = [@"string1", @"string2", @"string3", @"string4"];
I want to get each string object and assign to dynamically created NSString objects.
Is it possible?
I'm not quite sure what you are asking for.
You can have something like this:
typedef struct Array_s {
__strong id *values;
int count;
} Array;
#define array(values) ({ id _v[] = { values }; int _c = sizeof(_v) * sizeof(*_v); int *_cpy = malloc(sizeof(id) * _c); memcpy(_cpy, _v, sizeof(id) * _c); Array _a; _a.count = _c; _a.values = _cpy; _a; })
#define destroy(array) ({ free(array->values); })
And you can use this like this:
Array a = array(@"This", @"Is", @"A", @"Test");
for (int i = 0; i < a.count; i++)
{
NSLog(@"%@", a.values[i]);
}
destroy(a);
EDIT: It appears I read your question wrong.
NSArray *deepCopyArray(NSArray *input)
{
id copiedValues[input.count];
for (int i = 0; i < input.count; i++)
{
copiedValues[i] = [[input objectAtIndex:i] copy];
}
return [NSArray arrayWithObjects:copiedValues count:input.count];
}