0

Since I have opened my project with xcode 12 I am getting the following issue:

import UIKit

class PersonViewController: UIViewController {

override func viewDidLoad() {
  super.viewDidLoad()
  
  let imageView = UIImageView()
  let carImage = UIImage(named: "carImg")
  imageView.image = carImage
}
}

The error I am getting is: "No exact matches in reference to instance method 'image" The compiler is basically not recognising that UIImageView has a property called "image" or that UIKit is not imported.

If I create a new project this compiles just fine, so I am guessing it is some sort of setting that was fine in xcode11 but not fine in xcode12.

Note: This is an Objective C project with a few classes in Swift.

Note: Restarted my mac, did clean project and removed Derived Data

Joao Duarte
  • 321
  • 2
  • 10
  • 2
    If everything looks fine: Restart Xcode, restart the Mac. Xcode is just a program with bugs. This is very sad to say and used to be the Top-1-solution for MS Windows, but unfortunatly, Mac and Xcode are catching up rapidly. – Andreas Oetjen Sep 21 '20 at 19:13
  • 2
    I would also add a Clean project step in there, sometimes that does the trick. – jclasley Sep 21 '20 at 19:34

2 Answers2

-3

Are you missing an import of UIKit at the top of your file?

import UIKit

class PersonViewController: UIViewController {

    
    override func viewDidLoad() {
      super.viewDidLoad()
      
      let imageView = UIImageView()
      let carImage = UIImage(named: "carImg")
      imageView.image = carImage
    }
}
Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • 1
    this is not related with IBOutlet. The code should simply compile without any IBOutlet. It works fine in a fresh project – Joao Duarte Sep 21 '20 at 18:52
  • Oh, sorry. That will teach me to try to reply without looking at the question carfefully. Nevermind. – Duncan C Sep 21 '20 at 19:08
-4

class PersonViewController: UIViewController {

@IBOutlet weak var imageView: UIImageView! //This line is important and must not be excluded
Mohammad Kaif Ali
  • 151
  • 1
  • 1
  • 3