Exc*_*ion 1 arrays objective-c nsarray ios
我有一个数组包含每个索引的数组.
array is :(
(
"http://localhost/ColorPicker/upload/2014-01-14-04-01-19g1.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-20g2.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-20g3.jpg"
),
(
"http://localhost/ColorPicker/upload/2014-01-14-04-01-49y1.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-50y2.jpg"
),
(
"http://localhost/ColorPicker/upload/2014-01-14-04-01-50y3.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-51y6.jpg"
)
)
Run Code Online (Sandbox Code Playgroud)
我想制作一个类似的数组
(
"http://localhost/ColorPicker/upload/2014-01-14-04-01-50y3.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-51y6.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-50y3.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-51y6.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-50y3.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-51y6.jpg"
)
Run Code Online (Sandbox Code Playgroud)
如何在数组中消除(),()并创建包含url的单个数组.
你需要创建一个新的数组:
NSMutableArray *newArray = [[NSMutableArray alloc] init];
for (NSArray *a in array)
[newArray addObjectsFromArray:a];
Run Code Online (Sandbox Code Playgroud)
您可以使用键值编码运算符"@unionOfArrays"来展平数组:
NSArray *nested = @[@[@"A1", @"A2", @"A3"], @[@"B1", @"B2", @"B3"], @[@"C1", @"C2", @"C3"]];
NSArray *flattened = [nested valueForKeyPath:@"@unionOfArrays.self"];
NSLog(@"nested = %@", nested);
NSLog(@"flattened = %@", flattened);
Run Code Online (Sandbox Code Playgroud)
输出:
nested = (
(
A1,
A2,
A3
),
(
B1,
B2,
B3
),
(
C1,
C2,
C3
)
)
flattened = (
A1,
A2,
A3,
B1,
B2,
B3,
C1,
C2,
C3
)