Engr. Jawaid Ahmed Engr. Jawaid Ahmed - 2 months ago 36
iOS Question

I am getting this error "use of unresolved identifier 'personPic' "

I am making a face detection app. I have written some code for detection but I am geting an error. Kindly suggest men an alternate solution.
Here is the code, and the error is at line number 3.

import UIKit
import CoreImage

class ViewController: UIViewController ,UIAlertViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

@IBOutlet var imageView: UIImageView!
@IBAction func Moodify(_ sender: UIButton) {

let picker = UIImagePickerController(

picker.delegate = self
picker.allowsEditing = true
picker.sourceType = .camera
self.present(picker, animated: true, completion: { _ in })

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [AnyHashable: Any]) {
let chosenImage = info[UIImagePickerControllerEditedImage]
self.imageView!.image = chosenImage as? UIImage
picker.dismiss(animated: true, completion: { _ in })

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.dismiss(animated: true, completion: { _ in })


func detect() {

guard let personciImage = CIImage(image: personPic.image!) else {

let accuracy = [CIDetectorAccuracy: CIDetectorAccuracyHigh]
let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: accuracy)
let faces = faceDetector.featuresInImage(personciImage)

for face in faces as! [CIFaceFeature] {

print("Found bounds are \(face.bounds)")

let faceBox = UIView(frame: face.bounds)

faceBox.layer.borderWidth = 3
faceBox.layer.borderColor = UIColor.redColor().CGColor
faceBox.backgroundColor = UIColor.clearColor()

if face.hasLeftEyePosition {
print("Left eye bounds are \(face.leftEyePosition)")

if face.hasRightEyePosition {
print("Right eye bounds are \(face.rightEyePosition)")

override func viewDidLoad() {

let alert = UIAlertController(title: "Error", message: "Device has no camera", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)

/* if !UIImagePickerController.isSourceTypeAvailable(.camera) {
let myAlertView = UIAlertView (title: "Error", message: "Device has no camera", delegate: nil, cancelButtonTitle: "OK", otherButtonTitles: "")
} */

// Do any additional setup after loading the view, typically from a nib.

override func didReceiveMemoryWarning() {
// Dispose of any resources that can be recreated.




You need to declare it and connect to a UIImageView in storyboard.

@IBOutlet weak var personPic: UIImageView!

This is basic of ObjC programming. How can use something that you haven't declared, right? Ok good luck in your project.