Page tree
Skip to end of metadata
Go to start of metadata

Summary: This document provides information about the extension supporting iOS mobile applications written in Swift built with Xcode.

Extension ID

com.castsoftware.swift

What's new?

Please see the following pages for information about new features/changes, fixed bugs, changes that will impact results etc.:

Description

This extension provides support for iOS mobile applications written in Swift built with Xcode.

In what situation should you install this extension?

If you have an iOS mobile application written in Swift and built with Xcode and you want to view the source code object types and their links with other objects, then you should install this extension.

How CAST detects XCode projects

The Swift extension is dependent on the iOS Objective-C extension, which includes a discoverer that enables Xcode projects to be detected (see Xcode Discoverer). CAST will search for the project.pbxproj (or a .pbxproj file) - when one is found, the contents are inspected and are used to determine the list of projects present in the root folder.

What are the differences with the extension for iOS Objective-C?

The iOS Objective-C extension is aimed at analyzing iOS mobile applications written in Objective-C (and to a lesser extent C and C++) and built with XCode. The Swift extension can do the same thing, however, it also supports source code written using the Swift technology.

Supported Languages

The following languages used to write iOS mobile applications are supported by this extension:

TechnologySupportedNotes
Objective-C(tick)Supported via the dependent iOS - Objective-C extension.
C/C++(tick)
Swift(tick)-

Supported Versions

VersionSupported
3.2 - 5.2(tick)

Supported iOS and third-party frameworks

Please see the same section in the iOS Objective-C extension for more information.

Function Point, Quality and Sizing support

This extension provides the following support:

  • Function Points (transactions): a green tick indicates that OMG Function Point counting and Transaction Risk Index are supported
  • Quality and Sizing: a green tick indicates that CAST can measure size and that a minimum set of Quality Rules exist
Function Points
(transactions)
(tick)
Quality and Sizing(tick)

AIP Core compatibility

This extension is compatible with:

AIP Core release
Supported
8.3.x(tick)

Supported DBMS servers

This extension is compatible with the following DBMS servers:

DBMSSupported
CSS / PostgreSQL(tick)

Prerequisites

(tick)An installation of any compatible release of AIP Core (see table above)

Dependencies with other extensions

Some CAST extensions require the presence of other CAST extensions in order to function correctly. The Swift extension requires that the following other CAST extensions are also installed:

Note that when using the CAST Extension Downloader to download the extension and the Manage Extensions interface in CAST Server Manager to install the extension, any dependent extensions are automatically downloaded and installed for you. You do not need to do anything.

Download and installation instructions

You will need to manually install the extension using the Application - Extensions interface. When installed, follow the instructions below to run a new analysis/snapshot to generate new results:

Source code discovery

A discoverer (see Xcode Discoverer) is provided with the extension to automatically detect Xcode code: CAST will search for the project.pbxproj (or a .pbxproj file) - when one is found, the contents are inspected and are used to determine the list of projects present in the root folder. For every Xcode project located, one C/C++ Technology Analysis Unit will be created:

Analysis configuration

For each C/C++ Technology Analysis Unit created for an Xcode project discovered by CAST, the following options should be set as shown below:

Swift code Analysis Unit creation

A discoverer is provided with the extension to automatically detect Python code: a Python project will be discovered for the package's root folder when at least one .py or .jy (jython) file is detected in the root folder or any sub-folders. For every Python project located, one Universal Technology Analysis Unit will be created (new in 1.2.0 version):

TODO (JHU): image of created analysis unit, similar to Python doc.

Automatic exclusion of test and external dependency files from analysis

Analyzers are aimed at the study of the application source code. References and calls to external libraries are conveniently left out of the analysis, except for those that can be interpreted as elements taking part in a transaction, such as web service requests or database queries

The Swift analyzer will skip files found inside the two standard locations of the two leading dependency managers: \Carthage\Checkouts and Pods. On the other hand, all files found inside a folder (or within sub-folders) with name ending "Tests"  are considered as test files (consistent with Xcode conventions). This feature works upon detection of the project '.xcodeproj\' folder to assure the files belong to a Swift project. However, files with name ending as 'Tests.swift' are automatically skipped.

What results can you expect?

Once the analysis/snapshot generation has completed, you can view the results in the normal manner:

Objects

The following objects are displayed in CAST Enlighten:

Swift

IconDescription

Swift Class

Swift Enumeration

Swift Function

Swift Method

Swift Protocol

Swift SourceCode

Swift Structure

Default Property Initializer

Swift DELETE http service

Swift GET http service

Swift POST http service

Swift PUT http service

Tip

If your application is supposed to be communicating with services, ensure you have GET, POST, PUT, DELETE Service objects created after the analysis.

C/C++

IconDescription
Constructor
Class
Class Folder
Destructor
Directory
Enum
Enum Item
Free Function
Global Variable
Macro
Member Function
Member Variable
Namespace
Parameter
Root Directory
Source File
Template Class
Template Class Instance
Template Constructor
Template Constructor Instance
Template Free Function
Template Free Function Instance
Template Member Function
Template Member Function Instance
Template Parameter
Template Union
Template Union Instance
Typedef
Union
Additional File

iOS & Objective-C

IconDescription
Project
Workspace
Source File
Plist File
Story Board File
XIB File
UIApplication Delegate

UIApplication
Interface
Category

Protocol
Class Method

Method
Action
Get Resource Service
Post Resource Service
Put Resource Service
Delete Resource Service
Interface Variable
Outlet
Property
Property Getter
Property Setter
UI Button
UI Control
UI TextField

Structural Rules

The following structural rules are provided:

You can also find a global list here:

https://technologies.castsoftware.com/rules?sec=t_1055000&ref=||

Web Services

Web service queries are supported for URLSession and the third-party library Alamofire. The same web service objects are used for both of them. For the former, as an example, the code of the form as below will create a Swift Delete http service object with url "http://localhost:8001/rest/todos/{}":

func deleteTodo(str: String) {
	var urlString = "http://localhost:8001/rest/todos/" + str;
	guard let url = URL(string: urlString) else { return }
	var deleteTask = URLRequest(url: (url as URL?)!, ...)
	deleteTask.httpMethod = "DELETE"
	URLSession.shared.dataTask(with: deleteTask) {(data, response, error) in
		if let jsonData = try? JSONSerialization.jsonObject(with: data!, options: []) {
	…
	}.resume()
}

For Alamofire we support the request function. In the following example the web service call is represented by a Swift Get http service object

func getTodo(...) {
  guard let url = URL(string: "http://localhost:8001/rest/todos/") else {return}
  
  Alamofire.request(url, method: .get, ...)
  ...
  }
}

The (call) links from Swift objects (functions, methods, ...) to Swift Web Service objects will be created by the analyzer as well. Similar to other analyzers, the responsible of further linking Services and Operations (possible inter-technology) is the dependency extension com.castsoftware.wbslinker. A picture of a simple call-graph including StoryBoard objects as entry points and Web Services as end points is shown in the following section.

Transactions for Function Points

In the example below we illustrate the results one can expect concerning transactions. The call graph starts from the StoryBoard widgets (eg Button and TextField) which are by default set as entry points. The StoryBoard defining these widgets is interpreted by the Objective-C Analyzer. After this; the Swift analyzer will then generate the links between these widgets and Swift objects, such as functions and methods. Eventually the call graph might reach different end points contributing to function point counting. In this example most of the StoryBoard widgets finish calling web services (these could potentially call web service operations inside the very same application so that the transaction would continue):

Click to enlarge

Known Limitations

  • Some limitations come from the iOS extension, please refer to the iOS Objective-C extension documentation.
  • Some limitations come from the Objective-C analyzer, please refer to the iOS Objective-C extension documentation.
  • Violations localized in Class Property Initializer objects are not visible in the Dashboard (to be included in forthcoming releases).
  • Operator overloading and definition of custom operators is supported (at parsing level) but use of uncommon symbols may raise errors during the analysis.
  • Duplication of objects is avoided when preprocessing directives (#if, #endif) are used to specialize class, structure, prototype and Enum objects according to used frameworks. In the example below, a single Swift Structure object is generated, specifically, the first one appearing in the code:

#if os(iOS) || os(tvOS)
    import UIKit
    public struct TextInput<Base: UITextInput> {
    }
#endif
#if os(macOS)
    import Cocoa
    public struct TextInput<Base: NSTextInputClient> {
    }
#endif
  • No labels