Integrate into a Swift app

Now that you have created the Swift source files for extracting and serializing the report data to XML, you can integrate your reports into your application.

Establish a database connection and include the Swift source into your application by using one of the following methods:
  • Create a library using your data source
  • Link in the library into your application

Creating the dynamic library

The DataSourceLib node in a BAM Swift project is set up to create the dynamic library (.dylib).

To review the commands that create the dynamic library, select the DataSourceLib node in the Projects view, then select Tools > Specific setup > Edit Build Rules. Under the Build tab, you can view the rules that create the intermediate Swift files; under the Link >> Library tab, you can see where the .dylib file will be written.

Linking in the libraries

Before we look at the method that creates the report, take note of the import clause towards the start of the file and the resource it references:
import customlib

This is needed, as all generated data sources are contained in the library.

Regardless of the number of generated data sources, a single library is created that holds all the generated data sources. The library has a .dylib extension, for our example the file would be named libcustomlib.dylib. Now examine the properties for the application node, and you see the library referenced under the Linker options property with three parameters:
-I "/dir/path" -L "/dir/path" -lcustomlib 
where:
  • -I (a capital "i") specifies the path to the directory containing the library.
  • -L specifies the path to the directory containing the library.
  • -llibname is the name of the library prefaced with a lowercase "l".
Examine the Linker options specified for the ReportLauncher application in the OrderReoprtBam.4pw demo.
-I "$(ProjectDir)/bin" -L "$(ProjectDir)/bin" -lreporting 
In the ReportLauncher.swift file, we find:
import reporting

Configure and run the report

Examining the code included with the OrderReportBAMSwift.4pw, in the ReportLauncher.swift file.

  1. Configure the report.

    In this example, the report is configured to be output to PDF.

    // Configure the report execution to output an PDF file.
       let rcPtr = createRuntimeConfiguration(selectedReport)
       setOutputFileName(rcPtr, outputFilename)
       selectDevice (rcPtr, PDF)
       configureDistributedProcessing(rcPtr, "127.0.0.1", 7000)
  2. Instantiate the data source object from the data source library.
    guard let content_handler = createContentHandler(rcPtr)
  3. Pass the object to the report engine for processing.
    // Run the report.
       guard let _ = reportToRun.init(dbConnection!, content_handler) else
       {
           throw ReportLauncherError.UnableToRunReport
       }