How to create an array of strings or float in Objective-C

I need help here, I need to know how to create an array of strings extracted from the array. I use powerplot for the graph, and it only accepts a float or string array.

I need to create something like this dynamically.

NSString * sourceData [7] = {@ "2", @ "1", @ "4", @ "8", @ "14", @ "15", @ "10"};

Below is my code to find out the line numbers.

NSInteger drunked = [appDelegate.drinksOnDayArray count];
NSMutableArray * dayArray = [[NSMutableArray alloc] init];
NSMutableArray * sdArray = [[NSMutableArray alloc] init];
//float *sdArray[7];


for (int i=0; i<drunked; i++) {
    DayOfDrinks *drinksOnDay = [appDelegate.drinksOnDayArray objectAtIndex:i];
    NSString * dayString= [NSDate stringForDisplayFromDateForChart:drinksOnDay.dateConsumed];
    [dayArray addObject:dayString];
    NSLog(@"%@",[dayArray objectAtIndex:i]);

    drinksOnDay.isDetailViewHydrated = NO;
    [drinksOnDay hydrateDetailViewData];

    NSString * sdString= [NSString stringWithFormat:@"%@", drinksOnDay.standardDrinks];
    [sdArray addObject:sdString];

    NSString *tempstring;
    NSLog(@"%@",[sdArray objectAtIndex:i]);

}

thanks for the help:)

+5
source share
3 answers

An array in Objectice-C is not so difficult to work with:

NSMutableArray *myArray = [NSMutableArray array];
[myArray addObject:@"first string"]; // same with float values
[myArray addObject:@"second string"];
[myArray addObject:@"third string"];
int i;
int count;
for (i = 0, count = [myArray count]; i < count; i = i + 1)
{
   NSString *element = [myArray objectAtIndex:i];
   NSLog(@"The element at index %d in the array is: %@", i, element); // just replace the %@ by %d
}

NSArray NSMutableArray - , .

, :

http://www.cocoalab.com/?q=node/19

+7

(, , , Mutable :

NSMutableArray *myArray = [[NSMutableArray alloc] initWithObjects:@"2", @"1", @"4", @"8", @"14", @"15", @"10", nil];
[myArray addObject:@"22"];
[myArray addObject:@"50"];

//do something

[myArray release];
+1

malloc C-. - :

NSString **array = malloc(numElements * sizeof(NSString *))
some code here
free(array)

, NSMutable, c , , .

0

All Articles