Iphone 将字符串对象数组到字符串objective-c

Iphone 将字符串对象数组到字符串objective-c,iphone,objective-c,xcode,cocoa-touch,Iphone,Objective C,Xcode,Cocoa Touch,我有这个数组array*array=[@“string1”、@“string2”、@“string3”、@“string4”] 我想获取每个字符串对象并分配给动态创建的NSString对象 可能吗 我不太清楚你想要什么 你可以有这样的东西: typedef struct Array_s { __strong id *values; int count; } Array; #define array(values) ({ id _v[] = { values }; int _c =

我有这个数组
array*array=[@“string1”、@“string2”、@“string3”、@“string4”]

我想获取每个字符串对象并分配给动态创建的NSString对象


可能吗

我不太清楚你想要什么

你可以有这样的东西:

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); })
Array a = array(@"This", @"Is", @"A", @"Test");

for (int i = 0; i < a.count; i++)
{
    NSLog(@"%@", a.values[i]);
}

destroy(a);
你可以这样使用它:

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); })
Array a = array(@"This", @"Is", @"A", @"Test");

for (int i = 0; i < a.count; i++)
{
    NSLog(@"%@", a.values[i]);
}

destroy(a);
Array a=Array(@“This”、@“Is”、@“a”、@“Test”);
for(int i=0;i
编辑:看来我看错了你的问题

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];
}
NSArray*deepCopyArray(NSArray*input)
{
id copiedValues[input.count];
对于(int i=0;i
上述代码甚至在语法上都无效。什么是
数组
?方括号是什么意思?你是说,对于该数组中的每个NSString,你想要一个新的NSString,它是数组中字符串的副本?是的,这就是我想要的,这样我就可以将这些字符串分配给我的标签,在屏幕上显示嘿Richard谢谢,实际上情况是,我已经在核心数据中保存了名称,我将它们放在一个数组中,然后从该数组中我想将这些名称分配给屏幕上的每个标签