- Extension ID
- What's new?
- Description
- Supported Languages
- Supported Versions
- Supported iOS and third-party frameworks
- Function Point, Quality and Sizing support
- AIP Core compatibility
- Supported DBMS servers
- Prerequisites
- Dependencies with other extensions
- Download and installation instructions
- Source code discovery
- Analysis configuration
- What results can you expect?
- Known Limitations
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:
Technology | Supported | Notes |
---|---|---|
Objective-C | Supported via the dependent iOS - Objective-C extension. | |
C/C++ | ||
Swift | - |
Supported Versions
Version | Supported |
---|---|
3.2 - 5.2 |
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
- 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) | |
---|---|
Quality and Sizing |
AIP Core compatibility
AIP Core release | Supported |
---|---|
8.3.x |
Supported DBMS servers
This extension is compatible with the following DBMS servers:
DBMS | Supported |
---|---|
CSS / PostgreSQL |
Prerequisites
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:
- iOS - Objective-C
- Web services linker service (internal technical extension)
Download and installation instructions
The extension will not be automatically downloaded and installed in CAST Console. If you need to use it, should manually install the extension using the Application - Extensions interface:
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
No Analysis Units will be created automatically relating to the Swift source code - this is the expected behaviour, therefore you will need to create them manually.
AIP Console
Browse to the Application - Config panel and expand the Universal Technology option:
Click the Add button to create a new Analysis Unit:
Then configure the Analysis Unit, ensuring that you choose the Swift language (3):
CAST Management Studio
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
Icon | Description | Description | |
---|---|---|---|
Swift Class | Swift DELETE http service | ||
Swift Enumeration | Swift GET http service | ||
Swift Function | Swift POST http service | ||
Swift Method | Swift PUT http service | ||
Swift Protocol | |||
Swift SourceCode | |||
Swift Structure | |||
Default Property Initializer |
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++
Icon | Description |
---|---|
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
Icon | Description |
---|---|
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 extension documentation.
- Some limitations come from the Objective-C analyzer, please refer to the Objective-C Analyzer 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