iphone - Retain counts of IBOutlets -


while coding same questions concerning retain counts of iboutlets came along: retain count after unarchiving object nib? when use @property's iboutlet? retain or assign while setting? differences between mac , iphone?

so read the nib object life cycle apple's documentation. test apps on mac , iphone gave me strange results. nevertheless wrote down few rules how handle issue stay happy while coding wanted verify community , listen opinions , experiences:

  1. always create iboutlet top-level objects. non-top-level objects if necessary (access needed).
  2. always provide property follows iboutlets (and release them necessary!):
    • top-level objects on mac:
      • @property (nonatomic, assign) iboutlet someobject *someobject;
      • @synthesize someobject;
      • [self.someobject release];
    • non-top-level objects on mac (no release):
      • @property (nonatomic, assign) iboutlet nswindow *window;
      • @synthesize someobject;
    • top-level objects on iphone (must retain):
      • @property (nonatomic, retain) iboutlet someobject *someobject;
      • @synthesize someobject;
      • [self.someobject release];
    • non-top-level objects on iphone (should retain):
      • @property (nonatomic, retain) iboutlet uiwindow *window;
      • @synthesize window;
      • [self.window release];

side notes:

  • on mac , iphone outlet connections made setter if available.
  • top-level objects: "have [...] no owning object"
  • non-top-level objects: "any objects have parent or owning object, such views nested inside view hierarchies."

so question be: is correct , practice?

i hope can approve or correct it.

always have nibs' file's owner subclass of nswindowcontroller or nsviewcontroller (on mac os x) or uiviewcontroller (on iphone), , use @property (retain) iboutlet of outlets, doing appropriate releases in controller subclass -dealloc method.

this pattern work fine on both mac os x and iphone os, because nswindowcontroller , nsviewcontroller on mac os x take implicit ownership of top-level objects (and relinquish in own -dealloc methods), , iphone os doesn't take implicit ownership of top-level objects during nib loading.


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -