1

We are trying to use the iOS Affdex SDK with a bridging header (in Swift). Can you please help us how to go about this process. Also how can we display up emojis based on the SDK (agin using Swift).

ahamino
  • 634
  • 1
  • 4
  • 12

1 Answers1

4

Here are some links to help you with Objective-C to Swift naming conventions:

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html

I’ve attached a simple view controller class which shows how to use our SDK in Swift. Hopefully this will help you.

    class ViewController: UIViewController, AFDXDetectorDelegate {

    var detector : AFDXDetector? = nil

    override func viewDidLoad() {
        super.viewDidLoad()

        // create the detector
        detector = AFDXDetector(delegate:self, usingCamera:AFDX_CAMERA_FRONT, maximumFaces:1)
        detector?.setDetectEmojis(true)
        detector!.start()
    }

    func detectorDidStartDetectingFace(face : AFDXFace) {
        // handle new face
    }

    func detectorDidStopDetectingFace(face : AFDXFace) {
        // handle loss of existing face
    }

    func detector(detector : AFDXDetector, hasResults : NSMutableDictionary?, forImage : UIImage, atTime : NSTimeInterval) {
        // handle processed and unprocessed images here
        if hasResults != nil {
            // handle processed image in this block of code

            // enumrate the dictionary of faces
            for (_, face) in hasResults! {
                // for each face, get the rage score and print it
                let emoji : AFDXEmoji = face.emojis
                let rageScore = emoji.rage
                print(rageScore)
            }                
        } else {
            // handle unprocessed image in this block of code
        }
    }
Boisy Pitre
  • 156
  • 6
  • `public init!(delegate: AFDXDetectorDelegate!, using camera: AFDXCameraType, maximumFaces: UInt)` is deperecated as of Swift 3, any alternatives? – Ohad Navon Aug 08 '17 at 09:26