Documentation Language: Swift

Framework

OCL

A pure Swift implementation of the OMG Object Constraint Language (OCL) for model querying and constraint specification.

Overview

OCL provides a complete implementation of the Object Constraint Language (https://www.omg.org/spec/OCL/) standard in pure Swift. Use it to query models, specify constraints, and perform operations on collections, strings, and numeric values in a declarative, side-effect-free manner.

The framework follows the OMG OCL 2.4 specification (https://www.omg.org/spec/OCL/2.4/PDF), providing familiar OCL operations for developers experienced with Eclipse OCL (https://projects.eclipse.org/projects/modeling.mdt.ocl) or other OCL implementations whilst offering a modern, type-safe Swift API.

Key Features

Quick Example

import OCL

// Collection operations
let numbers = [1, 2, 3, 4, 5]
let evenNumbers = try OCL.select(numbers) { $0 % 2 == 0 }
// Result: [2, 4]

// String operations
let text = "Hello, World!"
let upper = try OCL.toUpperCase(text)
// Result: "HELLO, WORLD!"

// Numeric operations
let value = -42.7
let absolute = try OCL.abs(value)
// Result: 42.7

Topics

Essentials

A
Getting Started with OCL

Learn how to use OCL operations in your Swift projects.

A
Understanding OCL

Learn the fundamental concepts of the Object Constraint Language.

Standard Library

E
OCLUnaryMethod

Enumeration of OCL unary methods (methods that take only a receiver, no arguments).

E
OCLBinaryMethod

Enumeration of OCL binary methods (methods that take a receiver and one argument).

E
OCLTernaryMethod

Enumeration of OCL ternary methods (methods that take a receiver and two arguments).

Error Handling

E
OCLError

Errors that can occur during OCL operation evaluation.

Functions

F
abs(_:)

Returns the absolute value of a number.

F
add(_:_:)

Adds two values together.

F
and(_:_:)

Performs logical AND operation on two boolean values.

F
asBag(_:)

Converts a collection to a bag (allowing duplicates).

F
asOrderedSet(_:)

Converts a collection to an ordered set.

F
asSequence(_:)

Converts a collection to a sequence.

F
asSet(_:)

Converts a collection to a set by removing duplicates.

F
at(_:_:)

Returns the character at a specific position in a string.

F
ceiling(_:)

Returns the ceiling (smallest integer not smaller than the input) of a real value.

F
collect(_:_:)

Transforms each element of a collection using the given transform function.

F
concat(_:_:)

Concatenates two strings.

F
contains(_:_:)

Checks if a string contains a specified substring.

F
difference(_:_:)

Returns the difference between two collections.

F
divide(_:_:)

Divides the left value by the right value.

F
endsWith(_:_:)

Checks if a string ends with a specified suffix.

F
equals(_:_:)

Tests whether two values are equal.

F
excludes(_:_:)

Tests whether a collection does not contain a specific element.

F
excluding(_:_:)

Returns a new collection with all occurrences of an element removed.

F
exists(_:_:)

Tests whether at least one element in the collection satisfies the given predicate.

F
first(_:)

Returns the first element of a collection.

F
flatten(_:)

Flattens a nested collection structure.

F
floor(_:)

Returns the largest integer less than or equal to the value (OCL Real.floor()).

F
forAll(_:_:)

Tests whether all elements in the collection satisfy the given predicate.

F
greaterThan(_:_:)

Tests whether the left value is greater than the right value.

F
greaterThanOrEqual(_:_:)

Tests whether the left value is greater than or equal to the right value.

F
implies(_:_:)

Performs logical implication operation on two boolean values.

F
includes(_:_:)

Tests whether a collection contains a specific element.

F
including(_:_:)

Returns a new collection with an element added.

F
indexOf(_:_:)

Finds the index of the first occurrence of a substring within a string.

F
intersection(_:_:)

Returns the intersection of two collections.

F
invokeBinaryMethod(_:on:with:)

Invokes a binary method on a receiver value with one argument.

F
invokeTernaryMethod(_:on:with:and:)

Invokes a ternary method on a receiver value with two arguments.

F
invokeUnaryMethod(_:on:)

Invokes a unary method on a receiver value.

F
isEmpty(_:)

Tests whether a collection or string is empty.

F
iterate(_:_:_:)

Accumulates elements of a collection using the given accumulator function.

F
last(_:)

Returns the last element of a collection.

F
lessThan(_:_:)

Tests whether the left value is less than the right value.

F
lessThanOrEqual(_:_:)

Tests whether the left value is less than or equal to the right value.

F
max(_:_:)

Returns the maximum of two numeric values (OCL Integer/Real.max()).

F
min(_:_:)

Returns the minimum of two numeric values (OCL Integer/Real.min()).

F
modulo(_:_:)

Computes the remainder of dividing the left value by the right value.

F
multiply(_:_:)

Multiplies two values together.

F
negate(_:)

Performs numeric negation on a numeric value.

F
not(_:)

Performs logical NOT operation on a boolean value.

F
notEmpty(_:)

Tests whether a collection or string is not empty.

F
notEquals(_:_:)

Tests whether two values are not equal.

F
oclAsType(_:_:)

Casts an object to the specified type.

F
oclIsKindOf(_:_:)

Checks if an object is of the specified type or a subtype.

F
oclIsTypeOf(_:_:)

Checks if an object is exactly of the specified type.

F
oclIsTypeOfName(_:_:)

Checks if an object is of a specific ECore type by name.

F
oclTypeName(_:)

Gets the type name of an ECore value as a string.

F
one(_:_:)

Tests whether exactly one element in the collection satisfies the given predicate.

F
or(_:_:)

Performs logical OR operation on two boolean values.

F
power(_:_:)

Raises a numeric value to the power of another numeric value.

F
reject(_:_:)

Rejects all elements from a collection that satisfy the given predicate.

F
replaceAll(_:_:_:)

Replaces all occurrences of a substring with another string.

F
round(_:)

Returns the rounded value to the nearest integer (OCL Real.round()).

F
select(_:_:)

Selects all elements from a collection that satisfy the given predicate.

F
size(_:)

Returns the number of elements in a collection or characters in a string.

F
split(_:_:)

Splits a string into an array of substrings using a delimiter.

F
startsWith(_:_:)

Checks if a string starts with a specified prefix.

F
substring(_:_:_:)

Extracts a substring from a string.

F
subtract(_:_:)

Subtracts the right value from the left value.

F
toLowerCase(_:)

Converts a string to lowercase.

F
toUpperCase(_:)

Converts a string to uppercase.

F
trim(_:)

Trims whitespace from both ends of a string.

F
union(_:_:)

Returns the union of two collections.

See Also

Related Documentation