Using core data, how do I initialize the IVAR values? Analyzer gives me the error “Receiver in message expression is an uninitialized value”
Here is my snippet of code to call the object which is throwing the issue in analyzer :
CDCamera *camForAnnotation;
for(CDCamera *cams in fetchedObjects){
NSSet *annotSet = cams.annotation;
for (CDAnnotations *myannos in annotSet){
if (annotationIdentifer == [myannos objectID]) {
// found camera for annotation
camForAnnotation = cams;
bearing = myannos.bearing;
break;
}
}
}
double aov = [camForAnnotation.aov doubleValue] //Receiver in message expression is an uninitialized value
Here is my CDCamera .h:
#import <CoreData/CoreData.h>
@class CDAnnotations;
@interface CDCamera : NSManagedObject
{
}
@property (nonatomic, retain) NSString * notes;
@property (nonatomic, retain) NSNumber * lfl;
@property (nonatomic, retain) NSNumber * ccd_h;
@property (nonatomic, retain) NSNumber * aov;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * monitor_d_size;
@property (nonatomic, retain) NSSet* annotation;
@end
@interface CDCamera (CoreDataGeneratedAccessors)
- (void)addAnnotationObject:(CDAnnotations *)value;
- (void)removeAnnotationObject:(CDAnnotations *)value;
- (void)addAnnotation:(NSSet *)value;
- (void)removeAnnotation:(NSSet *)value;
- (NSManagedObjectID *) getNSManagedObjectID;
@end
Here is my .m
#import "CDCamera.h"
#import "CDAnnotations.h"
@implementation CDCamera
@dynamic notes;
@dynamic lfl;
@dynamic ccd_h;
@dynamic aov;
@dynamic name;
@dynamic monitor_d_size;
@dynamic annotation;
- (NSManagedObjectID *) getNSManagedObjectID{
return [self objectID];
}
@end
Thanks for your help.
You’re not guaranteed to have a value in camForAnnotation, if nothing matches inside your for loop.
You should initialize the value to nil when declaring it, and possibly wrap your subsequent code in an if statement to save running anything if camForAnnotation is still nil.