String

public extension String

This adds various functionality to the String class.

  • This was cribbed from here: https://stackoverflow.com/a/42912862/879365

    Declaration

    Swift

    var isAnInteger: Bool { get }

    Return Value

    true, if the string is all digits (an integer).

  • This tests a string to see if a given substring is present at the start.

    Declaration

    Swift

    func beginsWith(_ inSubstring: String) -> Bool

    Parameters

    inSubstring

    The substring to test.

    Return Value

    true, if the string begins with the given substring.

  • The following calculated property comes from this: http://stackoverflow.com/a/27736118/879365

    This extension function cleans up a URI string.

    Declaration

    Swift

    var urlEncodedString: String? { get }

    Return Value

    a string, cleaned for URI.

  • This was cribbed from here: https://stackoverflow.com/a/48867619/879365

    This is a quick “classmaker” from a String. You assume the String is the name of a class that you want to instantiate, so you use this to return a metatype that can be used to create a class.

    Declaration

    Swift

    var asClass: AnyClass? { get }

    Return Value

    a metatype for a class, or nil, if the class cannot be instantiated.

  • The following function comes from this: http://stackoverflow.com/a/27736118/879365

    This extension function creates a URI query string from given parameters.

    Declaration

    Swift

    static func queryStringFromParameters(_ parameters: [String : String]) -> String?

    Parameters

    parameters

    a dictionary containing query parameters and their values.

    Return Value

    a String, with the parameter list.

  • “Cleans” a URI

    Declaration

    Swift

    func cleanURI() -> String!

    Return Value

    an implicitly unwrapped optional String. This is the given URI, “cleaned up” (“http[s]://” may be prefixed).

  • “Cleans” a URI, allowing SSL requirement to be specified.

    Declaration

    Swift

    func cleanURI(sslRequired: Bool) -> String!

    Parameters

    sslRequired

    If true, then we insist on SSL.

    Return Value

    an implicitly unwrapped optional String. This is the given URI, “cleaned up” (“http[s]://” may be prefixed)