can I store an id value in array of float type?

I used, for(id value in values) to get the value from an NSArray. Now I want to store it in 2 dimensional float array[][]. When I try to assign the values to array it is giving error:incompatible types in assignment. I tried to cast the value but I got error: pointer value used where a floating point value was expected. I need to store the values in an 2 dimensional array . How can I make it ? Thank You.

@implementation fromFileRead1
NSString *fileNameString;
int numberOfEnemies, numberOfValues;
-(id)init
{
    if( (self = [super init]) ) 
    {
        NSString *path = @"/Users/sridhar/Desktop/Projects/exampleOnFile2/enemyDetals.txt";
        NSString *contentsOfFile = [[NSString alloc] initWithContentsOfFile:path];
        NSArray *lines = [contentsOfFile componentsSeparatedByString:@"\n"]; 
        numberOfEnemies = [lines count];
        NSLog(@"The number of Lines: %d", numberOfEnemies);
        for (id line in lines)
        {
            NSLog(@"Line %@", line );
            NSString *string1 = line;
            NSArray *split1 = [string1 componentsSeparatedByString:@","];
            numberOfValues = [split1 count];
            NSLog(@"The number of values in Row: %d", numberOfValues);
            for (id value in split1)
            {
                NSLog(@"value %@", value);
                float value1;
                value1 = [split1 objectAtIndex:2]);
                NSLog(@"VAlue of Value1 at index 2: %f", value1 );
            }
        }
    }
    return self;
}
@end

In enemyDetal.txt I have

1,3,3
2,3,2.8
10,2,1.6

Answers


Storing an object (e.g. id) in a float array is most certainly not what you want, and will give you the weirdest results.

The question is what you really want to do. If you have NSNumber objects in your array containing float values, then you can use [value floatValue] to convert your object to a float primitive.

If your intention was really to store a pointer as a float try (float)((int)value)). This might work but be warned that this you will most likely not be able to retrieve the pointer again.


Need Your Help

How to change the position of a comment box when hovered over it?

excel-vba vba excel

Ok, so I have changed the position of a comment box using VBA, but it only shows this new position when I click "edit/show comment". Why does it not show this new position when I hover over the cell?

MainActivity is not public

java android xml

I am getting a weird error in AndroidManifest.xml file saying "MainActivity is not public. Validate Resource reference inside Android XML files." Do not know how to solve the error. Can anyone help...