microsoft / Cognitive-Face-iOS

iOS SDK for the Microsoft Face API, part of Cognitive Services
https://www.microsoft.com/cognitive-services/en-us/face-api
Other
184 stars 64 forks source link

Problem with Detect method in swift 3 #13

Closed iseeya-app closed 7 years ago

iseeya-app commented 7 years ago

Hi,

I'm trying to use the library using swift 3 and ran into a issue while tying to use detect:

if I try and call the method like this:

client.detect(with: data, returnFaceId: true, returnFaceLandmarks: true, returnFaceAttributes: []) { (faces, error) in //...code... } everything works fine and i get the faces array correctly.

but when I try and add a face attribute type (instead of empty array as above), like this:

client.detect(with: data, returnFaceId: true, returnFaceLandmarks: true, returnFaceAttributes: [MPOFaceAttributeTypeAge, MPOFaceAttributeTypeHeadPose]) { (faces, error) in //...code... }

the program crashes with the following error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue isEqualToNumber:]: unrecognized selector sent to instance 0x1744502f0'

the error happens regardless of number and kind of MPOFaceAttributeType used any ideas ? perhaps some syntax issue I§m missing ?

Dave

ghost commented 7 years ago

I guess this problem is caused by that Swift enums are not compatible with Objective-C, but you can try converting to make it work. I got this work in swift 2.2 (I have not installed xcode 8 for some reason), hope it can help you:

client.detect(...., returnFaceAttributes:[NSInteger(MPOFaceAttributeTypeAge.rawValue), NSInteger(MPOFaceAttributeTypeGender.rawValue), NSInteger(MPOFaceAttributeTypeHeadPose.rawValue) ] )

iseeya-app commented 7 years ago

this solved the problem with same syntax for swift 3

thanks a lot cocof!!

Dave

huxuan commented 7 years ago

Close as problem solved.