StringProtocol
protocol StringProtocol : BidirectionalCollection, Comparable, ExpressibleByStringInterpolation, Hashable, LosslessStringConvertible, TextOutputStream, TextOutputStreamable where Self.Element == Character, Self.Index == String.Index, Self.StringInterpolation == DefaultStringInterpolation, Self.SubSequence : StringProtocol
These are a variety of cool String extensions that add some great extra cheese on the pizza.
-
Declaration
Swift
var localizedVariant: String { get }
Return Value
the localized string (main bundle) for this string.
-
From here: https://stackoverflow.com/q/24123518/879365, but modified from here: https://stackoverflow.com/a/55639723/879365
Declaration
Swift
var md5: String { get }
Return Value
an MD5 hash of the String
-
This extension lets us uppercase only the first letter of the string (used for weekdays). From here: https://stackoverflow.com/a/28288340/879365
Declaration
Swift
var firstUppercased: String { get }
Return Value
The string, with only the first letter uppercased.
-
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.
-
The opposite of the above
This extension function cleans up a URI string.
Declaration
Swift
var urlDecodedString: String? { get }
Return Value
a string, cleaned for URI.
-
This allows us to find the first index of a substring.
Declaration
Swift
func index(of inString: Self, options inOptions: String.CompareOptions = []) -> Index?
Parameters
of
The substring we’re looking for.
options
The String options for the search.
Return Value
The index of the first occurrence. Nil, if does not occur.
-
This allows us to find the last index of a substring.
Declaration
Swift
func endIndex(of inString: Self, options inOptions: String.CompareOptions = []) -> Index?
Parameters
of
The substring we’re looking for.
options
The String options for the search.
Return Value
The index of the last occurrence. Nil, if does not occur.
-
This returns an Array of indexes that map all the occurrences of a given substring.
Declaration
Swift
func indexes(of inString: Self, options inOptions: String.CompareOptions = []) -> [Index]
Parameters
of
The substring we’re looking for.
options
The String options for the search.
Return Value
an Array, containing the indexes of each occurrence. Empty Array, if does not occur.
-
This returns an Array of Index Ranges that map all the occurrences of a given substring.
Declaration
Swift
func ranges(of inString: Self, options inOptions: String.CompareOptions = []) -> [Range<Index>]
Parameters
of
The substring we’re looking for.
options
The String options for the search.
Return Value
an Array, containing the Ranges that map each occurrence. Empty Array, if does not occur.