After having implemented the design of your screen or cell, most of the times, some logic will be required to complete the screen. The logic of a screen is implemented in Editor Code. Let's explore what the Editor Code has to offer! To achieve that we will create a view controller, which we will name "screenToTest."

  • To go to Editor Code screen press the "CODE" button. 
  • To the top left section, you can see the name of your model. You can change it by pressing on it. You can also add tags to your model
  • Model variables

In this section, you can add and remove variable properties to your model, the "screenTest" screen in this case. Let's play around and create some variables.

Each variable consists of its name, the type of the value that will store and its value. When first adding a variable in Editor Code, you initially can only provide its name and value type but no value. That means that up until the time the variable is initialized, it cannot be used. 

Let's add a variable that we will name "stringVariable" and will have a type value of string. 

We only want one string to be stored so we will not initialize it as an array. If for example, we had a list of names, then we would create it as an array of strings. 

  • Protocols

By pressing Protocols, you will find all the protocols regarding your model. The number of the provided protocols varies according to the views add to your model. For example, if you have added a table view to your screen, TableViewDatasourceProtocol and TableViewDelegateProtocol. A protocol that will always appear is the "Recommended functions" that provides the users with some handy functions. Also, if a variable is added, there will be another protocol, the "didSet variables," that includes the didSet functions of all the variables. 

In our case, we have the "didSet stringVariable" function, that will be triggered, not when the variable is created, but as soon as the user sets the "stringVariable."

  • Functions

Functions are the logic of the model. If for example, you want something to happen or change when a button is tapped, that action should be a function. 

Let's add a function!

That's all folks!

Did this answer your question?