Reputation: 4699
Why I am getting a MSRangeException with this code:
NSArray *patientenVornamen = [NSArray arrayWithObjects:@"Michael", @"Thomas", @"Martin", nil];
NSArray *patientenNachnamen = [NSArray arrayWithObjects:@"Miller", @"Townsend", @"Mullins", nil];
NSArray *patientenWeiblich = [NSArray arrayWithObjects:NO, NO, NO , nil];
NSArray *patientenGeburtsdatum = [NSArray arrayWithObjects:[NSDate date], [NSDate date], [NSDate date], nil];
for (int i = 0; i < 3; i++) {
Patient *patient = [NSEntityDescription insertNewObjectForEntityForName:@"Patient" inManagedObjectContext:_coreDataHelper.context];
patient.vorname = [patientenVornamen objectAtIndex:i];
patient.nachname = [patientenNachnamen objectAtIndex:i];
patient.geburtsdatum = [patientenGeburtsdatum objectAtIndex:i];
patient.weiblich = [patientenWeiblich objectAtIndex:i];
}
Upvotes: 0
Views: 1819
Reputation: 1491
You cannot put a bool value as is. Instead use @(NO). That should work.
Upvotes: 1
Reputation: 9593
NSArray *patientenWeiblich = [NSArray arrayWithObjects:NO, NO, NO , nil];
You can't put primitive types into NSArray. In your case compiler is silent just because NO
is 0 which is effectively nil
. So, you get an empty NSArray.
You should wrap them with NSNumber
first:
NSArray *patientenWeiblich = [NSArray arrayWithObjects:@(NO), @(NO), @(NO) , nil];
And afterwards get the value with:
[[patientenWeiblich objectAtIndex:i] boolValue];
Upvotes: 2
Reputation: 7344
NO
is not an object but you need to store objects inside of an array. So
use [NSNull null]
or @(NO
) instead of NO
.
Upvotes: 0