String

extension String

This adds various functionality to the String class.

  • Declaration

    Swift

    var firstUppercased: String { get }

    Return Value

    The String, with just the first letter uppercased.

  • 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 function comes from this: http: //stackoverflow.com/a/27736118/879365

    This extension function cleans up a URI string.

    Declaration

    Swift

    func URLEncodedString() -> String?

    Return Value

    a string, cleaned for URI.

  • 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.