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: Bill Cheeseman <email@hidden>
- Date: Wed, 09 Mar 2016 08:59:38 -0500
> On Mar 9, 2016, at 8:42 AM, Roland King <email@hidden <mailto:email@hidden>> wrote:
>
> just
>
> return NSApp.mainWIndow?.contentViewController as? MainContentViewController
>
> works without all the guard and intermediate variables and still returns the same optional.
Thanks. I should have remembered this is a more direct way to do it:
lazy var mainContentViewController: MainContentViewController? = {
NSApp.mainWindow?.contentViewController as? MainContentViewController
}()
But the main thrust of my question was whether this is a safe and sensible way to crossreference other storyboard scenes -- at least when prepareForSegue(_:sender:) isn't available, as it isn't here. Having thought about it for a while now, I guess it is a sensible approach. It has less to do with storyboards than with the longstanding fact that NSApplication has a 'mainwindow' property and NSWindow has a 'contentViewController' property.
--
Bill Cheeseman - email@hidden <mailto:email@hidden>
_______________________________________________
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