• 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: Why does Xcode define IBOutlet with @synthesize?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why does Xcode define IBOutlet with @synthesize?


  • Subject: Re: Why does Xcode define IBOutlet with @synthesize?
  • From: Jerry Krinock <email@hidden>
  • Date: Fri, 23 Sep 2011 22:08:43 -0700

On 2011 Sep 23, at 15:57, Quincey Morris wrote:

> a. What do you mean by "unnecessary"? Your choices for an outlet are pretty much ivar or property. Are you suggesting the property is "unnecessary" because it could be an ivar instead?

Yes.  After studying this some more I see that, in older code, I did not declare outlets as properties.  Instead, I put the IBOutlet directive on the ivar,

@interface MyWinCon : NSWindowController
{
    IBOutlet FooView *m_fooView ;
}

and then if I wanted other objects to be able to access these, instead of declaring a property I would declare and implement a getter

- (FooView*)fooView {
    return m_fooView ;
}

> b. @dynamic isn't magic. It says the methods are provided by something else (other than user-written implementations or @synthesized implementations).  What's the something else you're thinking of here?

The "something" is that I thought the IBOutlet tells the compiler to access instance variables directly.  After reading Greg Parker's responses and the links, I see that the executable actually is different if an outlet is @synthesize vs. @dynamic.  If you use @synthesize, it really does synthesize setters and getters, and these really are used during nib loading.  If you use @dynamic, setters and getters are not synthesized, and nib loading accesses instance variables directly using, for instance, object_setInstanceVariable().

So now I understand that if an outlet is declared as an @property, as Xcode has been doing in recent versions, it needs to be implemented, for example by @synthesize.  Using @dynamic would be wrong because it allows me to write code that invokes, e.g., -[MyWinCon fooView], which would cause a "method not found for selector" runtime exception.

Actually, the old way still seems more straightforward, but anyhow I see how it works now.

Thank y'all.

_______________________________________________

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

References: 
 >Why does Xcode define IBOutlet with @synthesize? (From: Jerry Krinock <email@hidden>)
 >Re: Why does Xcode define IBOutlet with @synthesize? (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Why does Xcode define IBOutlet with @synthesize?
  • Next by Date: Re: What is the likely reason why objects aren't being loaded from a XIB?
  • Previous by thread: Re: Why does Xcode define IBOutlet with @synthesize?
  • Next by thread: Re: Why does Xcode define IBOutlet with @synthesize?
  • Index(es):
    • Date
    • Thread