logo
down
shadow

NSArray of doubles iOS (Objective c)


NSArray of doubles iOS (Objective c)

By : Ramya
Date : November 17 2020, 03:01 PM
it fixes the issue In swift you could do this with a map statement. In Objective-C you must have an NSArray of NSNumbers. It's not possible to have an NSArray of a value type like double in Objective-C. (It is possible - normal, even - to have a C array of floating point values, but I don't think that's what you're talking about.)
Try code like this:
code :
NSArray <NSString *>*mapArrayOfNumbers(NSArray <NSNumber *> *sourceArray) {
    NSMutableArray *result = [NSMutableArray arrayWithCapacity: sourceArray.count];
    for (NSNumber *aNumber in sourceArray) {
        [result addObject:[NSString stringWithFormat: @"%.02f", aNumber.doubleValue]];
    }
    return result;
}
NSArray <NSNumber *> *numbers = @[@(1.1), @(2.2), @(3.4567), @(8.901234), @(9.876543)];
NSArray <NSString *> *strings = mapArrayOfNumbers(numbers);
for (NSString *aString in strings) {
    NSLog(@"Entry = %@", aString);
}


Share : facebook icon twitter icon
filtering NSArray into a new NSArray in Objective-C

filtering NSArray into a new NSArray in Objective-C


By : BJoe
Date : March 29 2020, 07:55 AM
I wish this help you NSArray and NSMutableArray provide methods to filter array contents. NSArray provides filteredArrayUsingPredicate: which returns a new array containing objects in the receiver that match the specified predicate. NSMutableArray adds filterUsingPredicate: which evaluates the receiver’s content against the specified predicate and leaves only objects that match. These methods are illustrated in the following example.
code :
NSMutableArray *array =
    [NSMutableArray arrayWithObjects:@"Bill", @"Ben", @"Chris", @"Melissa", nil];

NSPredicate *bPredicate =
    [NSPredicate predicateWithFormat:@"SELF beginswith[c] 'b'"];
NSArray *beginWithB =
    [array filteredArrayUsingPredicate:bPredicate];
// beginWithB contains { @"Bill", @"Ben" }.

NSPredicate *sPredicate =
    [NSPredicate predicateWithFormat:@"SELF contains[c] 's'"];
[array filteredArrayUsingPredicate:sPredicate];
// array now contains { @"Chris", @"Melissa" }
Passing Objective-C objects from NSArray to NSArray

Passing Objective-C objects from NSArray to NSArray


By : user3283287
Date : March 29 2020, 07:55 AM
seems to work fine Assuming the non-conformant objects are not being retained elsewhere, your assumption is correct with the following caveats:
Search a NSArray of ints or doubles

Search a NSArray of ints or doubles


By : user3619808
Date : March 29 2020, 07:55 AM
like below fixes the issue
This works great for the variables that are NSStrings, however, there are some that are ints or doubles, and this code crashes when it trys to sort these.
How to use NSArray of NSArray object in objective c?

How to use NSArray of NSArray object in objective c?


By : Syvertson
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I declared a NSArray object in .h file as , Try this :
code :
NSArray  *obj1 = [[NSArray alloc] initWithObjects:@"1",@"0",@"0",nil];
NSArray  *obj2 = [[NSArray alloc] initWithObjects:@"0",@"3",@"0",nil];
NSArray  *obj3 = [[NSArray alloc] initWithObjects:@"0",@"0",@"5",nil];

scnArray = [[NSArray alloc] initWithArray:obj1];
scnArray = [scnArray arrayByAddingObjectsFromArray:obj2];
scnArray = [scnArray arrayByAddingObjectsFromArray:obj3];
create a method that sets textlabel.text to nsarray at index(x) while x<nsarray.count objective c

create a method that sets textlabel.text to nsarray at index(x) while x<nsarray.count objective c


By : nz881
Date : March 29 2020, 07:55 AM
around this issue Your mySplit variable is local to arrayfromfile, so once that method returns the variable has gone. There is more than one approach to solving this. One is making it an instance variable, that is a variable that belongs to your current class instance and is visible to every instance method. Start you implementation like this:
code :
@implementation MyClassName
{
    NSArray *mySplit;
}
shadow
Privacy Policy - Terms - Contact Us © voile276.org