Question: I would like to access a variable from my rootViewController from within a different viewController (it‘s a CollectionViewCell).

```
window!.rootViewController = ViewController()

```

I declare the var like so:

```
import UIKit

class ViewController: UIViewController {

    var testString : String = "Test";

    override func viewDidLoad() {    
[…]

```

And try to access it this way:

```
import UIKit

class MainCollectionViewCell: UICollectionViewCell {
    override init(frame: CGRect) {
        […]
        super.init(frame: frame)

        let mainView = self.window!.rootViewController
        var testStringFromMainView = mainView.test
[…]

```

But all I keep getting is:

```
Type of expression is ambiguous without more context

```

Strange thing is, when I try for example

```
mainView.view.backgroundColor = UIColor.redColor()

```

it works.

I can’t figure out what I am doing wrong. Any help is appreciated!

Answer: 
I got the same problem as yours,and I tried portfoliobuilder's way but it didn't work.
And then I just make some changes on my code,then it worked.
I just set every instance of my button an OnlickListener interface instead of letting my Class inplements the View.OnClickListener~

```
button.setOnclickListener(new View.OnClickListener){
public void onClick(View v){//...
}
}

```

INSTEAD OF

```
public YourClass implements View.OnClickListener{...
public void OnClick(View v){
switch(v.getId()){
case://...
break;}}}

```
None of the solutions above worked to me. Pretty strange bug, wondering if some view is intercepting the touch events and broking it, maybe some appcompat stuff, there is a lot of touch intercepts over there…

Anyway, I workarounded the problem adding a transparent `View` over my real broken button and adding the click listener on this view, pretty ugly but it worked `¯\_(ツ)_/¯`

e.g. imagine the error happened in this layout:

```
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="16dp">

    <Button
        android:id="@+id/broken_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="0dp"
        android:layout_marginTop="0dp"
        android:text="Hello world" />

</RelativeLayout>

```

I added the transparent view and I set the click on it.

```
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="16dp">

    <Button
        android:id="@+id/broken_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="0dp"
        android:layout_marginTop="0dp"
        android:text="Hello world" />

    <View
        android:id="@+id/workaround_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/broken_button"
        android:layout_alignTop="@+id/broken_button"
        android:layout_alignEnd="@+id/broken_button"
        android:layout_alignBottom="@+id/broken_button" />

</RelativeLayout>

```

Again, it is an ugly solution, but still a solution.