ios - Need help on my tiny objective-c class design. How can I access my instance var? -
i playing around tiny app should store notes. ui uses master/detail view template.
my masterview
holds instance of notecontroller
in turn holds notes stored in array. save array using nskeyarchiver
. know there method applicationdidenterbackground
implemented in appdelegate.m
.
but can't call instance method of notecontroller
appdelegate
. creating new instance wouldn't work neither data lost. what's wrong design?
i hope it's clear problem is. appreciated.
note.m:
@interface note : nsobject @property (nonatomic, copy) nsstring *title; @property (nonatomic, copy) nsstring *content; @property (nonatomic, strong) nsdate *creationdate; @end
notecontroller.m:
@class note; @interface notedatacontroller : nsobject @property (nonatomic, retain) nsmutablearray *masternotelist; @property (nonatomic, copy) nsstring *datafilepath; - (nsuinteger) countoflist; - (note*) objectinlistatindex:(nsuinteger)theindex; - (void) addnote:(note*)thenote; - (void) removenote:(nsuinteger)theindex; - (void) loadmasterlist; - (void) savemasterlist; @end
my recommendation save note
possible. if when -addnote:
note
realized (has title, content, etc.), preserve , there in adding. well, when -removenote:
, save "notes file".
this simplifies matters, encapsulates management of notes
notecontroller
, , avoids having things somehow jack appdelegate
.
however, if approach not work you, if need save when app enters background, have notecontroller
observe uiapplicationdidenterbackgroundnotification
, notecontroller
have handler that end saves. mindful tho saving upon entering background may not ideal: if app exits before happens (e.g. crashes)? also, switching background isn't time engage in lengthy tasks, note
preservation may not best suited time.
Comments
Post a Comment