Re: Safe cross references between scenes in an OS X storyboard
Re: Safe cross references between scenes in an OS X storyboard
- Subject: Re: Safe cross references between scenes in an OS X storyboard
- From: Quincey Morris <email@hidden>
- Date: Wed, 09 Mar 2016 16:22:12 -0800
- Feedback-id: 167118m:167118agrif8a:167118sJH2UrsytG:SMTPCORP
On Mar 9, 2016, at 13:31 , Bill Cheeseman <email@hidden> wrote:
>
> static var controller: MainContentViewController? {
> get {
> return MainContentViewController.controller
> }
> set(newController) {
> MainContentViewController.controller = newController
> }
> }
No, it’s *really* a property, so like this:
> class MainContentViewController: NSWindowController {
>
> static private(set) var controller: MainContentViewController! // defaults to nil until set
>
> override func windowDidLoad () {
> precondition (MainContentViewController.controller== nil)
> MainContentViewController.controller = self
> }
> }
It’s a “regular” stored property, so you don’t have to write a setter or getter. (Your original version really is recursive.)
I’ve declared the property “private(set)” so that no one outside the class can change it, and I’ve added a check that there’s only one MainContentViewController ever created.
_______________________________________________
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