From the course: Practical Design Patterns in Swift

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Consolidating complex functionality

Consolidating complex functionality - Swift Tutorial

From the course: Practical Design Patterns in Swift

Start my 1-month free trial

Consolidating complex functionality

- [Instructor] In the following demo, we're going to build a Facade class that provides a simplified interface to work with the Natural Language framework. We start with the playground called NLPFacadeDemo. I'm going to add a new source file, so let's reveal the navigator. And I add a new file called NLPFacade. The first step is to import the Natural Language framework. Next, I create a public class called NLPFacade. NLPFacade. This class will expose a couple of public methods. The first method will return the dominant language of the input text. I make it a class method and call it dominantLanguage for string. The input string should be of type String and the return type is also a String. The method analyzes the input text and returns the language or nil if it can't recognize the language. That's why we have an optional String as a return type. To identify the language, we rely on the NLLanguageRecognizer class. I create a constant called language equals NLLanguageRecognizer, and…

Contents