• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects)


  • Subject: Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects)
  • From: Brian Stern <email@hidden>
  • Date: Tue, 18 Nov 2008 01:14:03 -0500


On Nov 18, 2008, at 12:59 AM, Roland King wrote:



Hey Brian -

Outlets for iPhone OS are established by calling setValue:forKeyPath:. The behavior of setValue:forKeyPath: is that if a setter exists, it is called. If a setter does not exist, the instance variable is looked up and set directly, and if it is an object, it is retained. This means that for IBOutlets, with no setters, they're retained in iPhone OS. This is different from Mac OS X. If you're writing code on both platforms, or are planning to, you should always use properties on both platforms since it makes the decision to retain outlets explicit and obvious.


How come the documentation that mmalc quoted doesn't have this clear statement?


which one did he quote, the one I suggested to you has it .. it's under Nib Object Retention. It's a page I have bookmarked because as I switch between iPhone and regular OSX I like to remind myself what it says. It's pasted below.

Yes, that's it. I've read it plenty of times.




iPhone OS - managed memory model

Objects in the nib file are created with a retain count of 1 and then autoreleased. As it rebuilds the object hierarchy, however, UIKit reestablishes connections between the objects using the | setValue:forKey:| method, which uses the available setter method or retains the object by default if no setter method is available.

I admit that I didn't internalize this statement because the behavior is different from the Mac. I also didn't internalize this because it seems to contradict the standard Cocoa memory management rules. My code doesn't retain the outlets so it shouldn't have to release them.


If you define outlets for nib-file objects, you should also define a setter method for accessing that outlet.

Why SHOULD?

Setter methods for outlets should

Why SHOULD?

retain their values, and setter methods for outlets containing top- level objects must retain their values to prevent them from being deallocated. If you do not store the top-level objects in outlets, you must retain either the array returned by the | loadNibNamed:owner:options:| method or the objects inside the array to prevent those objects from being released prematurely.

In a nib loaded by UIViewController I have no access to the top level objects array so this isn't usually relevant.


The shoulds in there confused me. The fact that the behavior is different from the Mac confused me. The fact that the behavior seems contrary to standard Cocoa memory management rules confused me. I assure you that I'm not the only person confused by this and who doesn't understand this.
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects)
      • From: Jonathan Hess <email@hidden>
References: 
 >Interface Builder & Wiring Objects (From: Greg Deward <email@hidden>)
 >Re: Interface Builder & Wiring Objects (From: Randall Meadows <email@hidden>)
 >Re: Interface Builder & Wiring Objects (From: Greg Deward <email@hidden>)
 >Re: Interface Builder & Wiring Objects (From: Andy Lee <email@hidden>)
 >Re: Interface Builder & Wiring Objects (From: mmalcolm crawford <email@hidden>)
 >Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects) (From: mmalcolm crawford <email@hidden>)
 >Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects) (From: Brian Stern <email@hidden>)
 >Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects) (From: Luke the Hiesterman <email@hidden>)
 >Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects) (From: Brian Stern <email@hidden>)
 >Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects) (From: Luke the Hiesterman <email@hidden>)
 >Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects) (From: Roland King <email@hidden>)
 >Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects) (From: Brian Stern <email@hidden>)
 >Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects) (From: Jonathan Hess <email@hidden>)
 >Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects) (From: Brian Stern <email@hidden>)
 >Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects) (From: Roland King <email@hidden>)

  • Prev by Date: Re: Question about interface builder
  • Next by Date: Re: NSDocument annoying warning
  • Previous by thread: Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects)
  • Next by thread: Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects)
  • Index(es):
    • Date
    • Thread