Re: nonatomic vs atomic assign/retain
Re: nonatomic vs atomic assign/retain
- Subject: Re: nonatomic vs atomic assign/retain
- From: glenn andreas <email@hidden>
- Date: Wed, 07 Sep 2011 13:06:28 -0500
On Sep 7, 2011, at 12:51 PM, Torsten Curdt wrote:
>>> So far I have never had to set an outlet itself in code myself. Do
>>> people really do this?
>>
>> It's not common, but the point remains, outlets are not at all immutable.
>
> AFAIK AppKit only writes to the outlets once. You may only access
> outlets only after a documented safe point. If one assumes that AppKit
> does not need synchronized access to the outlets during NIB loading
> the need for synchronization would depend entirely on how we as
> developers use the outlets. So whether they are technically immutable
> or not does not even matter. The question is whether synchronization
> is needed or not.
>
> Of course if would be nicer if outlets would be declared as read-only
> and only the NIB loading had write access somehow - but I guess that's
> not in the cards.
>
> Anyway. But I am curious - can you provide an example where you
> modified an outlet?
On iOS, a common technique to make complex table view cells is to put them in their own nib files, have a table view controller have:
@property (nonatomic, retain) IBOutlet UITableViewCell *loadedCell;
and then:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: self.identifier];
if (!cell) {
[[NSBundle mainBundle] loadNibNamed:@"ComplexTableViewCell" owner:self options:nil];
cell = [[self.loadedCell retain] autorelease];
self.loadedCell = nil;
}
// configure and return cell...
}
Not to mention that retained IB outlets also need to be nil'ed out when the view is unloaded...
Glenn Andreas email@hidden
The most merciful thing in the world ... is the inability of the human mind to correlate all its contents - HPL
_______________________________________________
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