Re: Swift: Trying to use ViewController(). to access object
Re: Swift: Trying to use ViewController(). to access object
- Subject: Re: Swift: Trying to use ViewController(). to access object
- From: "Eric E. Dolecki" <email@hidden>
- Date: Mon, 19 Oct 2015 20:53:52 +0000
By effect I meant it works as expected. Even when I set a variable to that
ViewController, I get the error. I am asking if there is a way to call a
method or set a property on an ViewController object from another class.
let foo = ViewController()
foo.object.hidden = true
Something like that, but which works.
On Mon, Oct 19, 2015 at 3:38 PM Jens Alfke <email@hidden> wrote:
>
> On Oct 19, 2015, at 11:12 AM, Eric E. Dolecki <email@hidden> wrote:
>
> I have been using NSNotificationCenter to affect objects in other classes
> to good effect.
>
>
> I don’t understand … that class is used to register notification observers
> and to post notifications. What do you mean by “affect”?
>
> *ViewController().someObject.hidden = true*
>
>
>
> When I compile and run, I get a EXC_BAD_INSTRUCTION at that line.
>
>
> That line doesn’t make sense to me. `ViewController()` will create a new
> ViewController instance, but you’re never assigning it to a variable or
> property, so it’s probably going to be dealloced after this line returns.
> So this doesn’t really do anything.
>
> I know it exists in the ViewController scope before my line is called.
>
>
> Again, I’m not sure what that means. Especially since the ViewController
> object doesn’t exist before that line is called.
>
> —Jens
>
_______________________________________________
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