konturgestaltung
konturgestaltung

Reputation: 467

Bad Access Code 1: Accessing Object instance Variables

I have built up an array of objects, created from a class, I wrote before. I just wanted to access some of the class variables while looping through the array:

- (void)viewDidLoad
{
       [super viewDidLoad];

       NSMutableArray *medicalCenters = [(AppDelegate *)[[UIApplication sharedApplication] delegate] medicalCenters];

       for (MedicalCenter *row in medicalCenters){
           NSString *latitude = row.MCLatitude;
           NSLog(@"%@", latitude);
       }
}

the Class File I've created look like this:

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface MedicalCenter : NSObject
{
    CLLocationCoordinate2D _coordinate;
}

@property (nonatomic, strong) NSString *medicalCenter;
@property (nonatomic, assign) NSString *MCLatitude;
@property (nonatomic, assign) NSString *MCLongitude;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

- (id)initWithName:(NSString *)medicalCenter coordinate:(CLLocationCoordinate2D)coordinate;

@end

Whenever I built up the NSString *latitude = row.MCLatitude, I got the message: Bad_excess Code:1

But when I just list the objects in the array medicalCenters, I can see them all............ Did I miss something important?

Thanks Sebastian

Upvotes: 0

Views: 2843

Answers (1)

X Slash
X Slash

Reputation: 4131

That's because of bad memory management, MCLatitude and MCLongitude property are set with (assign), they're not being retained properly, don't know the reason you set them up as assign, no reason that I can see, so if you change them to be strong, and use setter to assign the value, it should be fine.

@property (nonatomic, strong) NSString *MCLatitude;
@property (nonatomic, strong) NSString *MCLongitude;

Upvotes: 1

Related Questions