Ramon Vasconcelos Ramon Vasconcelos - 1 year ago 117
Swift Question

SFSpeechRecognizer init not accepting Locale

I'm trying to initialise an instance of

but I get the following error
Cannot convert value of type 'Locale' to expected argument type 'Locale'
which doesn't make any sense to me. Bellow is my initialisation code.

let speech = SFSpeechRecognizer(locale: Locale().initWithLanguageCode(languageCode: "en-US") as! Locale)

Answer Source

It should be:

if let speech = SFSpeechRecognizer(locale: Locale(identifier: "en-US")) {
     // ...

Use init(localeIdentifier:) for initialization.

let locale = Locale()

This causes:

enter image description here

Note that speech is an optional.

ALSO: here you can check iOS Locale Identifiers.

Hope this helped.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download