core data - Why does an unsaved managedObject lose its managedObjectContext -


currently, developing app book cars. booking related data stored in entity 'bookings'. attributes of 'bookings' or relationships between 'bookings' , other enties mandatory decided add managedobjects of entity 'bookings' own managedobjectcontext. context stored in separate variable avoid losing it. works fine unless i'll sign (enterprise store or adhoc) app , deploy it. arc enabled.

class bookings interface

@interface bookings : nsmanagedobject { @private      nsmanagedobjectcontext *mcontext; }  @end 

class bookings implementation

@implementation bookings {      + (bookings *)booking {          nsmanagedobjectcontext *context = [[nsmanagedobjectcontext alloc] initwithconcurrencytype:concurrencytype];          [context setpersistentstorecoordinator:[self persistentstorecoordinator]];           bookings *object = (bookings*)[[nsmanagedobject alloc] initwithentity:[self entityforname:pname] insertintomarenagedobjectcontext:context];          [object setsomereservationdata:...];          ...           // here store context in ivar of booking object          [object->mcontext = context];           return object;     } } 

at state booking object not saved!

class bookingsvc

bookings *booking = [bookings booking]; nslog(@"context: %@", [booking managedobjectcontext]); 

nothing saved or altered context null.

console output on device (adhoc signed , deployed via iphone-configurator or testflight)

... context: (null) 

console output on simulator or device (adhoc signed installed via xcode)

... context: <nsmanagedobjectcontext: 0x893c520> 

so why unsaved managedobject lose managedobjectcontext , how can avoided? bug or expected behavior?

your context nullified @ end of function. see here
object disowned context making properties null, in debug mode there exists autorelease pool keeping context being deallocated.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -