Note that there are some explanatory texts on larger screens.

plurals
  1. POmemory management and class member variable
    text
    copied!<p>I have the following code:</p> <pre><code> @interface Reservation : RKObject { NSNumber * _uid; NSNumber * _did; NSNumber * _rid; NSString* _origin; NSString* _destination; NSString* _time_range; NSDate * _start_date; NSDate * _end_date; } @property (nonatomic, retain) NSDate * start_date; @property (nonatomic, retain) NSDate * end_date; @property (nonatomic, retain) NSNumber * uid; @property (nonatomic, retain) NSNumber * did; @property (nonatomic, retain) NSNumber * rid; @property (nonatomic, retain) NSString * time_range; @property (nonatomic, retain) NSString * origin; @property (nonatomic, retain) NSString * destination; @end #import "Reservation.h" @implementation Reservation @synthesize time_range= _time_range; @synthesize origin=_origin; @synthesize destination=_destination; @synthesize uid=_uid; @synthesize did=_did; @synthesize rid=_rid; @synthesize start_date=_start_date; @synthesize end_date=_end_date; + (NSDictionary*) elementToPropertyMappings { return [NSDictionary dictionaryWithKeysAndObjects: @"TIME_RANGE", @"time_range", @"ORIGIN_ADDRESS", @"origin", @"DESTINATION_ADDRESS", @"destination", @"UID", @"uid", @"DID", @"did", @"RID", @"rid", @"START_DATETIME", @"start_date", @"END_DATETIME", @"end_date", nil]; } /* + (NSDictionary*)elementToRelationshipMappings { return [NSDictionary dictionaryWithKeysAndObjects: @"NSDate", @"start_date", @"NSDate", @"end_date", nil]; } */ - (void)dealloc { [_start_date release]; [_end_date release]; [_uid release]; [_did release]; [_rid release]; [_origin release]; [_destination release]; [_time_range release]; //[_deal release]; //[_route release]; [super dealloc]; } </code></pre> <p>@end</p> <pre><code>@interface ReservationViewController : UIViewController &lt;UITableViewDelegate, UITableViewDataSource, RKObjectLoaderDelegate&gt;{ Reservation * myres; } @property (nonatomic, retain) Reservation * myres; #import "ReservationViewController.h" @implementation ReservationViewController @synthesize myres; - (IBAction)makeReservation:(id)sender { self.myres = [[[Reservation alloc] init] autorelease]; myres.start_date = [df dateFromString:[NSString stringWithFormat:@"%@ %@", [self.data objectForKey:@"date"], [self.data objectForKey:@"start_time"]]]; myres.end_date = [df dateFromString:[NSString stringWithFormat:@"%@ %@", [self.data objectForKey:@"date"], [self.data objectForKey:@"end_time"]]]; NSLog(@"date is %@", myres.start_date); } - (void)objectLoader: (RKObjectLoader*) objectLoader didLoadObjects:(NSArray *)objects { Interval * res_int = [[Interval alloc] init]; res_int.date1 = myres.start_date; //why is it null here res_int.date2 = myres.end_date; //why is it null here res_int.rid = [[objects objectAtIndex:0] rid]; [[LocationDictionary sharedLocationDictionary] addLocationtoDictionary:[self.data objectForKey:@"route"] withKey:res_int]; </code></pre> <p>}</p> <p>The question is why is <code>res_int.date1</code> null when I tried printing it out? When I print myres.start_date inside the method makeReservation, it prints appropriately Can someone explain this to me and how to fix it?</p> <p><strong>UPDATE:</strong></p> <p>I have done the following at my setter:</p> <pre><code>-(void) setStart_date:(NSDate *) boo { NSAssert(boo != nil, @"why is this nil"); _start_date = boo; } </code></pre> <p>at the end the stack trace I got is:</p> <pre><code> *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'why is this nil' *** Call stack at first throw: ( 0 CoreFoundation 0x019ac5a9 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x01b00313 objc_exception_throw + 44 2 CoreFoundation 0x01964ef8 +[NSException raise:format:arguments:] + 136 3 Foundation 0x014013bb -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116 4 Project 0x00012d42 -[Reservation setStart_date:] + 194 5 Foundation 0x0137e5e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285 6 Project 0x0004c7b3 -[RKObjectMapper updateModel:ifNewPropertyValue:forPropertyNamed:] + 172 7 Project 0x0004cd55 -[RKObjectMapper setPropertiesOfModel:fromElements:] + 754 8 Project 0x0004d8f3 -[RKObjectMapper updateModel:fromElements:] + 50 9 Project 0x0004bb7a -[RKObjectMapper mapObject:fromDictionary:] + 201 10 Project 0x0004ba42 -[RKObjectMapper mapObject:fromString:] + 148 11 Project 0x0004927b -[RKObjectLoader processLoadModelsInBackground:] + 537 12 Foundation 0x01370cf4 -[NSThread main] + 81 13 Foundation 0x01370c80 __NSThread__main__ + 1387 14 libSystem.B.dylib 0x931a085d _pthread_start + 345 15 libSystem.B.dylib 0x931a06e2 thread_start + 34 ) terminate called after throwing an instance of 'NSException' </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload