Ramon Vasconcelos Ramon Vasconcelos - 3 months ago 48
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)


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.