• 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
Swift: Trying to use ViewController(). to access object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Swift: Trying to use ViewController(). to access object


  • Subject: Swift: Trying to use ViewController(). to access object
  • From: "Eric E. Dolecki" <email@hidden>
  • Date: Mon, 19 Oct 2015 18:12:47 +0000

I have been using NSNotificationCenter to affect objects in other classes
to good effect. However, is it possible to do something like this:

*ViewController().someObject.hidden = true*

When I compile and run, I get a EXC_BAD_INSTRUCTION at that line.

*fatal error: unexpectedly found nil while unwrapping an Optional value. *

I know it exists in the ViewController scope before my line is called. I
get autocomplete in Xcode for the object too.

I can't import the ViewController in Swift. Is there a simple trick to get
this to work to avoid using NSNotificationCenter in many places? I can
still do that but the ViewController().

Thanks,
Eric
_______________________________________________

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


  • Follow-Ups:
    • Re: Swift: Trying to use ViewController(). to access object
      • From: Jens Alfke <email@hidden>
  • Prev by Date: App keeps being told to open nonexistent doc on launch
  • Next by Date: titleForHeaderInSection wrong section count.
  • Previous by thread: Re: App keeps being told to open nonexistent doc on launch
  • Next by thread: Re: Swift: Trying to use ViewController(). to access object
  • Index(es):
    • Date
    • Thread