On Mar 9, 2016, at 13:31 , Bill Cheeseman <wjcheese...@gmail.com> 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to