In this article, you will learn how to use the shared library in the IOS application where we are going to display a simple message – “Application running on: iOS 13”. 

Follow the steps given below to set up the project.

  • Run the script ./gradlew :SharedCode:packForXcode in the Main project directory where you have the SharedCode project to generate the xcode-framework.
  • Open Xcode and go to the General settings. Add the full path of SharedCode/build/xcode-framework/sharecode.framework into the Frameworks and libraries section as shown in the diagram.
  • Copy and paste the path of the xcode-framework to the Build settings > Search Paths > Framework Search path.
  • Open the Build phase tab, add the run script and set the shell script as:
  • Drag the Run Script to be the second phases.

Now, the SharedCode can be used in the MultiplatformApp IOS project. Before we import it, let’s create a UI element called labels in the Main.storyboard to display our message. You can do it by clicking on the library button and dragging the labels into the phone screen.

  • Click on the Assistant button to open the ViewController.Swift file. Your editor should look like this:
  • Right-click on the label and drag the New referencing outlet button to the ViewController code. Give a name to the label in the ViewController as “label” as shown in the diagram below. Doing so will map the label widget and the @IBOutlet variable. IBOutlet is an Interface Builder Outlet that provides the connection between the UI components and the properties in the swift code.
  • Ensure that your UI element label is added in the ViewController.swift class.
  • Now, import the SharedCode into the ViewController and set the text of the label to the getMessage() function present in the Common.kt file of the shared library.
  • Run the app to see the message.

Well done! we have finished our first Android and IOS App using shared Kotlin library. This is a very simple application which we can leverage it to add some real-world functionality like reading data from the remote API. In the next articles, you will learn to read data from a remote API. Stay tuned.

Tags

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *