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.
- 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 . 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
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.
-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".
-I "$(ProjectDir)/bin" -L "$(ProjectDir)/bin" -lreporting
import reporting
Configure and run the report
Examining the code included with the OrderReportBAMSwift.4pw, in the ReportLauncher.swift file.
- 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)
- Instantiate the data source object from the data source
library.
guard let content_handler = createContentHandler(rcPtr)
- Pass the object to the report engine for processing.
// Run the report. guard let _ = reportToRun.init(dbConnection!, content_handler) else { throw ReportLauncherError.UnableToRunReport }