I want to create function to return a 1d array with 2 elements in it something like below :
(NSArray *) myFunction {
NSArray * myArr = [[NSArray alloc]initwithobjects:[NSNumbers numberwithfloat:1.0f],[NSNumbers numberwithfloat:1.0f]];
//the above line is just pseudo code
}
but when I want to retrieve nsarray form this function i want to do it at the simplest way
which it seems impossible in objective-c
this is what I’ve written to get two simple float value which is not appropariate but i don’t have any further knowledge of how to doing it in simpler way
NSArray *tt2 = [[NSArray alloc] initWithArray:[self myFunction]];
float fp1=0.0f;
float fp2=0.0f;
BOOL firstTime = YES;
for(NSNumber *n in tt2)
{
if (firstTime) {
NSLog(@"%@" , n);
fp1 = [n floatValue];
firstTime = NO;
}
else {
fp2 = [n floatValue];
}
}
above code is ridiculos but i don’t have any other choice unless you advice me how can I convert a nsarray to nsnumber then a nsnumber to float[]
If you’re only storing floats, you could just use a C array instead. NSArray can only store objects.
However, it looks like you haven’t heard of the
objectAtIndexmethod?Does that help with your situation, it isn’t really clear what you’re trying to do from the question.