Configure Tifig

Congratulations, you just downloaded and installed Tifig and are now prepared to configure it for your first Swift project.

Goals

  1. Choose a workspace
  2. Set the Swift perspective
  3. Configure the toolchain

1. Choose a Workspace

The first time you start Tifig, you will be asked to enter a workspace. The wizard looks as follows:

Workspace Selection

You can either type or paste a path directly into the dropdown menu or search for a directory using the Browse button on the right.

If you don’t want this wizard to show every time you start up Tifig, you can check the box at the bottom left of the wizard to set your new workspace as the default.

When you are done, click on the Launch button.

2. Set the Swift Perspective

After successfully setting the workspace, the splash screen with the Tifig logo will show. You can see in the progress bar (below the logo) how the various plug-ins of the IDE are loaded.

Because it is the first time you started Tifig, you will be greeted by the welcome screen:

Welcome Screen

From here you can directly create a new Swift project or learn more about Swift from various resources. In this tutorial, we will first make sure that your IDE is correctly configured and therefore, we recommend that you close the welcome screen tab by clicking the close symbol on the top left.

After doing so, the blank view of your newly created workspace will appear:

Empty Workspace

Notice the Swift logo on the top right of the window? Clicking on it enables the Swift perspective in your IDE. Normally, the Swift perspective is set as the default and should be enabled already. If this is not the case, click on the logo to switch to the Swift perspective.

3. Configure the Toolchain

Tifig does not come with a built-in Swift installation. However, if you followed the installation instructions in the download section, Tifig should have set your Swift toolchain already. To verify this, open the Preferences.

Note: The Preferences are not located in the same menus on a Mac and on a Linux system, respectively. On a Mac, the path is Tifig/Preferences…. On a Linux system, the path is Window/Preferences.

In the Preferences, choose Swift Toolchains. The wizard looks as follows:

Swift Toolchains

If you had a Swift installation before opening Tifig, an initial entry should be present and selected in the toolchain list. If this is not the case, you can add your preferred toolchain by using the Add… button on the right of the list. You can also edit, duplicate and remove existing entries.

Summary

You have successfully prepared Tifig for your first Swift project by choosing the Swift perspective and setting your Swift toolchain. To find out how to create, change and run your first Swift project, go to our next tutorial.

Your First Project

In this short tutorial, you will create and run your first Swift project using Tifig.

Goals

  1. Create a project
  2. Make changes
  3. Run the project

1. Create a Project

There are several ways to open the New Swift Project wizard. Choose one of the following:

  • Right-click in the Project Explorer window. Select New/Swift Project.
  • Choose File/New/Swift Project from the main menu.
  • On the welcome screen (see Configure Tifig), click on Create Swift Project.

After doing so, the wizard shown below opens:

New Project Wizard

Here, you have to choose a name for your project. We chose Hello_Tifig, but you can choose whatever name you like.

The wizard has checked the box for using the default location, which creates a folder with your project name in your current workspace. If you want, you can change this by unchecking the box and providing an alternative location.

Tifig differentiates between three project types:

  • Empty
  • Executable
  • Library

For our example, we will stick with the executable project.

Click Finish to return to the main window, which now looks as follows:

Initial Project

As you can see, the parts that have changed are highlighted in red rectangles and numbered from 1 to 3. We will discuss each of the changes separately below.

  1. Project File Structure

    If you have a closer look at the Project Explorer window, you can see that Tifig has created some files and folders for you.

     .
     └── Hello_Tifig
         ├── Package.swift
         └── Sources
             └── Hello_Tifig
                 └── main.swift
    
    

    The main folder has the name of your project. In our case, this is Hello_Tifig. In it, a Sources/Hello_Tifig folder has been created, containing the main.swift file. This file will be our main focus in this tutorial.

    In addition, your project folder contains a Package.swift file. This file will be further discussed in the Using the Swift Package Manager tutorial.

  2. The main.swift File

    The name of this file is not set by accident. The main.swift file is used as the entry point of your entire application. By default, the newly created file has the following content:

     print("hello, world")
    

    As you probably would have guessed, this application prints hello, world to your console when being executed.

  3. Console Output

    Having clicked on Finish in the New Swift Project wizard, Tifig has already started working for you. On the bottom, you can see the output of the Swift compiler. If you have configured your toolchain correctly, you should get something similar to the following:

     Build Mode: auto
     Command: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift build
     Compile Swift Module 'Hello_Tifig' (1 sources)
     Linking ./.build/x86_64-apple-macosx10.10/debug/Hello_Tifig
     Exit Value = 0
    

    If your console does not show this, it is possible that the indexer is still running. You can check that by looking at the bottom right corner of Tifig. If the indexer is still running, you will see the word Indexer and a blue progress indicator (see screenshot above).

2. Make changes

You can make changes to your files by just typing them in the main.swift window. Saving your changes will trigger the Swift compiler to start a new build, which you can see in your console output. In our example, we replaced print("hello, world") with print("Hello Tifig"), matching our project name. Tifig now looks as follows:

Changed Project

3. Run the Project

To run your project, you can do one of the following:

  • Click on the green Run Button in the toolbar on the top.
  • Choose Run/Run from the main menu.

If everything works out, the console output should display Hello Tifig, as in the screenshot below:

Running Project

Summary

Congratulations, you have just created, changed and run your first Swift project in Tifig. Of course, this example shows the most simple project, having no other dependencies than the Swift standard library and only consisiting of a single file. To find out how you can manage dependencies using the Swift Package Manager, go to our next tutorial.

Using the Swift Package Manager

In this tutorial, you will learn how to manage dependencies using the Swift Package Manager. For this, we will create a small application that uses a predefined package. If you want to look at a more challenging example, you can visit the swift.org documentation.

Goals

  1. Add a dependency to your project
  2. Create a small application that uses the dependency

1. Add a Dependency to Your Project

Tifig already prepared your project for the inclusion of packages. Open the Package.swift file from your existing Hello_Tifig project by double-clicking it in the Project Explorer window. The following was already created for you:

// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "Hello_Tifig",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "Hello_Tifig",
            dependencies: []
        )
    ]
)

The library you are going to use is located on GitHub. It defines the following two public functions:

public func sayHello() {
    print("Hello Tifig")
}

public func sayGoodBye() {
    print("Goodbye Tifig")
}

To use these two functions, you have to make some adjustments to your Package.swift file:

  • In the dependencies section, add the following line:
.package(url: "https://github.com/pipeaesac/Hello_Tifig_Library.git", from: "1.0.0"),

This tells the package manager where the dependency is located and which versions are allowed to be used with your application.

  • In the targets section, add "Hello_Tifig_Library" to the already existing but so far empty target dependency list.

Your resulting Package.swift file should look as follows:

// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "Hello_Tifig",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
        .package(url: "https://github.com/pipeaesac/Hello_Tifig_Library.git", from: "1.0.0"),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "Hello_Tifig",
            dependencies: ["Hello_Tifig_Library"]
        )
    ]
)

That is all it takes. The Hello_Tifig_Library is now ready to be used in your application.

2. Create a Small Application That Uses The Dependency

To use the newly included library, replace the existing code in your main.swift file with the following:

import Hello_Tifig_Library

sayHello()
sayGoodBye()

When saving, the dependency will be downloaded and a file called Package.resolved will be created. It contains a description of your resolved dependency:

{
  "object": {
    "pins": [
      {
        "package": "Hello_Tifig_Library",
        "repositoryURL": "https://github.com/pipeaesac/Hello_Tifig_Library.git",
        "state": {
          "branch": null,
          "revision": "980d2afceb985a5598d7bc6116557b75469857f2",
          "version": "1.0.0"
        }
      }
    ]
  },
  "version": 1
}

Now you can go ahead and run your application. After completing all of the above steps, Tifig should look like this:

Finished Project

Summary

You have successfully finished all the tutorials and are now ready to start using Tifig. We hope you will enjoy working on your Swift projects with it.

If you have ideas or wishes for further tutorials, please let us know.