0

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];
}
mrd
  • 4,561
  • 10
  • 54
  • 92

3 Answers3

2
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];
kovpas
  • 9,553
  • 6
  • 40
  • 44
1

You cannot put a bool value as is. Instead use @(NO). That should work.

Vincent Zgueb
  • 1,491
  • 11
  • 11
0

NO is not an object but you need to store objects inside of an array. So use [NSNull null] or @(NO) instead of NO.

Pfitz
  • 7,336
  • 4
  • 38
  • 51