-1

In my ViewController, I have three UIImageView objects which are IBOutlet connections as well:

class ViewController: UIViewController {
   @IBOutlet weak var myImg1: UIImageView!
   @IBOutlet weak var myImg2: UIImageView!
   @IBOutlet weak var myImg3: UIImageView!

   //ERROR: Instance member 'myImg1' cannot be used by type 'ViewController'
   var myImgArr:[UIImageView] = [myImg1, myImg2, myImg3]
   ...
}

I try to put all the three UIImageView objects into an array myImgArr , but I got complier error : Instance member 'myImg1' cannot be used by type 'ViewController' , why? how to get rid of this error?

Leem.fin
  • 40,781
  • 83
  • 202
  • 354

1 Answers1

0

The problem is that you're accessing self before the class was initialised.

you can define it like this: var myImgArr:[UIImageView]

and then in the init method you can do myImgArr = [myImg1, myImg2, myImg3]

Please see the full answer here : Whats wrong here: Instance member cannot be used on type

Community
  • 1
  • 1
Eli Braginskiy
  • 2,867
  • 5
  • 31
  • 46