Reputation: 508
I want to print array element line by line like periodic table , here is my code..
NSArray* myInfo1 = [NSArray arrayWithArray:allhrStartTime];
[myInfo1 componentsJoinedByString:@"\n"];
NSArray* myInfo2 = [NSArray arrayWithArray:allhrStopTime];
[myInfo2 componentsJoinedByString:@"\n"];
NSArray* myInfo3 = [NSArray arrayWithArray:allhrStartLocation];
[myInfo3 componentsJoinedByString:@"\n"];
NSArray* myInfo4 = [NSArray arrayWithArray:allhrStopLocation];
[myInfo4 componentsJoinedByString:@"\n"];
NSArray* allInfo = [NSArray arrayWithObjects:headers, myInfo1,myInfo2 ,myInfo3,myInfo4, nil];'
Upvotes: 1
Views: 356
Reputation: 53000
As @Larme stated in a comment you are calling a method which returns a value but not using that value. You also appear to have some confusion between types.
Try this:
NSString *allhrStartTimeString = [allhrStartTime componentsJoinedByString:@"\n"];
NSLog(allhrStartTimeString);
The first line takes your original array and joins the values in it, separating each by a new line, to produce a string. The second line shows that string on the console. You should see the one element per line you seek.
However your code suggests you want the contents of each array to appear as a column in the output producing a tabular result. To do that you'll need to do a bit more work:
NSMutableString
appendFormat:
add the first line containing the headers to this mutable stringix
= 0 to maximum index of your column arrays
appendFormat:
again add the next two to your mutable string using the ix
'th element of each of your arrays (allhrStartTime
, allhrStopTime
, allhrStartLocation
, allhrStopLocation
)NSLog
.If you have difficulty coding this ask a new question, link to this one so people know the history, show the code you have written, and explain where you are having difficulty. Someone will undoubtedly help you along. HTH
Upvotes: 1