Skip to content

Latest commit

 

History

History

SwiftUtilities

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

SwiftUtilities

The SwiftUtilities package provides various tools and utility functions that are useful in sample code and in tests for those examples.

The included utility functions are as follows:

String

The String class is extended with the following functions:

uniqueName(withPrefix:withExtension:isValid) -> String

Generates a guaranteed-unique name which can be used for anything from unique strings in an array to names for files, S3 buckets, data objects, or any other named object.

Parameters

  • withPrefix: A string used at the beginning of the specified name. By default, no prefix is applied.

  • withExtension: A string specifying an extension to add to the end of the name, for file names. Do not include the period (".") in the string; it is added for you. By default, no extension is added.

  • isValid: A Boolean indicating whether or not the generated name should be a valid one. For the purposes of this function, it is assumed that a valid name cannot start with a comma (","), and should not include either numbers or the percent ("%") symbol. Between these, the resulting string is usually not valid for most use cases. By default, this is false, which causes a valid name to be returned.

Return value

A String containing the generated unique name. The name is a UUID, although it might be altered based on the provided options.

withLoremText(paragraphs:) -> String

Returns a Lorem Ipsum-style string containing the specified number of randomly generated paragraphs. If paragraphs is not specified, then five paragraphs of Lorem Ipsum text are returned. Each paragraph is four to eight sentences long, and each sentence contains three to nine words.

The Lorem Ipsum text is suitable for use in test files and example strings because it doesn't need translation and it doesn't unnecessarily make test code larger than necessary.

Parameters

  • paragraphs: The number of paragraphs to generate. If not specified, the resulting string contains five paragraphs.

Return value

A String containing up to paragraphs paragraphs of Lorem Ipsum-style generated text.

Testing

This package includes automated tests for each function. Before you run the tests, make sure you configure your environment to allow access to AWS and download and install the Swift tools if you don't already have them.

To run the tests, make sure you have Swift installed, then issue the command swift test to run the tests.

$ cd SwiftUtilities
$ swift test

The tests will compile and run, outputting the results to the console. You can also run the tests in Xcode if you prefer.


Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0