Functions are the way to implement complex logic in your application, compared to what No Code Event Actions can offer. By using Code Blocks in your Functions, you can create advanced and unique features in your applications, similar to the features built using Swift or Objective-C code. Most of the Code Blocks available in Kodika are using the native iOS code directly to have similar performance and backward compatibility.
A Function in Kodika contains a group of actions executed in a specific order when the Function is called/executed. You can have if conditions and for loops in your functions.
In order to be able to use the function with different parameters, you can use Function arguments. Function arguments are dynamic properties that are set during the execution of the Function by the caller.
For example, to create a function that sums two numbers and then multiplies them by 100, you can add two Function Arguments, and each time you execute the Function, you will change the result by changing the arguments.
Your functions can either return a value using the return argument, or do not return anything.
- Function with return argument: Calculate and return the product’s final cost after a discount.
- Function without return argument: Change the color of a button if the product out of stock.
Function properties can be used to temporarily store values during the function execution. Function properties are generated when the execution starts and destroyed as soon as the Function is finished. You cannot access their value outside of the Function, but you can return the value of a function property by setting the property as the return argument value or assign it to a Data Type property.
For example: When implementing a function that returns the sum of two integers
int2, you could create a
sum function property, assign its value to the sum of these two integers and place it in the return input of the function block.
- Open the Screen/Model/Cell that you want to edit.
- Go to the Code section.
- Press the + Add Function button.
- Type the name of your Function and press CREATE.
To go to the Code Blocks editor, press on the Function you want to edit.
You can delete a Function with Control+Click on it (tap and hold for iPadOS), and then press Delete.
Note: You cannot delete functions that are in use by an Event Action.
You can execute a function using its Code Block in another Function. You will find a Code Block for each created Function in Blocks -> Screens/Models/Cells -> Name of Data Type that has the Function.
There are some special functions that are automatically executed by the operating system when something specific happens, similar to the Events. You can find a list of those functions in the protocols section.