Functions
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.
What is a Function
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.
Arguments
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.
Result - Return Argument
Your functions can either return a value using the return argument, or do not return anything.
Examples
- 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
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 int1
, 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.
Manage Functions
Add Function
- 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.
Edit Function
To go to the Code Blocks editor, press on the Function you want to edit.
Delete Function
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.
Execute Functions
Using Event Actions
You can use a function with an Execute a Function Event Action, for example when a button pressed and calls the On Click Event.
In Code Blocks
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.
Automatically Executed Functions
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.