Name | Type | iOS | tvOS | watchOS | macOS |
---|---|---|---|---|---|
base64Decoded |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
base64Encoded |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
camelCased |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
containEmoji |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
firstCharacter |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
hasLetters |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
hasNumbers |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
isAlphabetic |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
isAlphaNumeric |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
isEmail |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
isValidUrl |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
isValidHttpsUrl |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
isValidHttpUrl |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
isValidSchemedUrl |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
isNumeric |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
lastCharacter |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
latinized |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
length |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
lines |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
mostCommonCharacter |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
reversed |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
bool |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
date |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
dateTime |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
double |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
float |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
int |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
int16 |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
int32 |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
int64 |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
int8 |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
url |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
trimmed |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
unicodeArray |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
urlDecoded |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
urlEncoded |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
withoutSpacesAndNewLines |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
subscript(i: Int) |
Method | 8+ | 9+ | 3+ | 10.10+ |
subscript(range: CountableRange<Int>) |
Method | 8+ | 9+ | 3+ | 10.10+ |
subscript(range: ClosedRange<Int>) |
Method | 8+ | 9+ | 3+ | 10.10+ |
copyToPasteboard() |
Method | 8+ | - | - | 10.10+ |
camelize() |
Mutating Method | 8+ | 9+ | 3+ | 10.10+ |
contain(_ string: String, caseSensitive: Bool) |
Method | 8+ | 9+ | 3+ | 10.10+ |
count(of string: String, caseSensitive: Bool) |
Method | 8+ | 9+ | 3+ | 10.10+ |
end(with suffix: String, caseSensitive: Bool) |
Method | 8+ | 9+ | 3+ | 10.10+ |
firstIndex(of string: String) |
Method | 8+ | 9+ | 3+ | 10.10+ |
latinize() |
Mutating Method | 8+ | 9+ | 3+ | 10.10+ |
random(ofLength: Int) |
Static Method | 8+ | 9+ | 3+ | 10.10+ |
replacing(_ substring: String, with newString: String) |
Method | 8+ | 9+ | 3+ | 10.10+ |
reverse() |
Mutating Method | 8+ | 9+ | 3+ | 10.10+ |
slicing(from i: Int, length: Int) |
Method | 8+ | 9+ | 3+ | 10.10+ |
slice(from i: Int, length: Int) |
Mutating Method | 8+ | 9+ | 3+ | 10.10+ |
slicing(from start: Int, to end: Int) |
Method | 8+ | 9+ | 3+ | 10.10+ |
slice(from start: Int, to end: Int) |
Mutating Method | 8+ | 9+ | 3+ | 10.10+ |
slicing(at i: Int) |
Method | 8+ | 9+ | 3+ | 10.10+ |
slice(at i: Int) |
Mutating Method | 8+ | 9+ | 3+ | 10.10+ |
splitted(by separator: Character) |
Method | 8+ | 9+ | 3+ | 10.10+ |
start(with prefix: String, caseSensitive: Bool) |
Method | 8+ | 9+ | 3+ | 10.10+ |
date(withFormat format: String) |
Method | 8+ | 9+ | 3+ | 10.10+ |
trim() |
Mutating Method | 8+ | 9+ | 3+ | 10.10+ |
truncate(toLength: Int, trailing: String?) |
Mutating Method | 8+ | 9+ | 3+ | 10.10+ |
truncated(toLength: Int, trailing: String?) |
Method | 8+ | 9+ | 3+ | 10.10+ |
urlDecode() |
Mutating Method | 8+ | 9+ | 3+ | 10.10+ |
urlEncode() |
Mutating Method | 8+ | 9+ | 3+ | 10.10+ |
* |
Infix Operator | 8+ | 9+ | 3+ | 10.10+ |
init?(base64: String) |
Optional Initializer | 8+ | 9+ | 3+ | 10.10+ |
init(randomOfLength: Int) |
Initializer | 8+ | 9+ | 3+ | 10.10+ |
nsString |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
lastPathComponent |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
pathExtension |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
deletingLastPathComponent |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
deletingPathExtension |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
pathComponents |
Read-Only Property | 8+ | 9+ | 3+ | 10.10+ |
appendingPathComponent(_ str: String) |
Method | 8+ | 9+ | 3+ | 10.10+ |
appendingPathExtension(_ str: String) |
Method | 8+ | 9+ | 3+ | 10.10+ |
--
String decoded from base64 (if applicable).
- type: Read-Only Property.
- return type: String?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"SGVsbG8gV29ybGQh".base64Decoded = Optional("Hello World!")
--
String encoded in base64 (if applicable).
- type: Read-Only Property.
- return type: String?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hello World!".base64Encoded -> Optional("SGVsbG8gV29ybGQh")
--
CamelCase of string.
- type: Read-Only Property.
- return type: String
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"sOme vAriable naMe".camelCased -> "someVariableName"
--
Check if string contains one or more emojis.
- type: Read-Only Property.
- return type: Bool
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hello 😀".containEmoji -> true
--
First character of string (if applicable).
- type: Read-Only Property.
- return type: String?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hello".firstCharacter -> Optional("H")
--
Check if string contains one or more letters.
- type: Read-Only Property.
- return type: Bool
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"123abc".hasLetters -> true
"123".hasLetters -> false
--
Check if string contains one or more numbers.
- type: Read-Only Property.
- return type: Bool
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"abcd".hasNumbers -> false
"123abc".hasNumbers -> true
--
Check if string contains only letters.
- type: Read-Only Property.
- return type: Bool
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"abc".isAlphabetic -> true
"123abc".isAlphabetic -> false
--
Check if string contains at least one letter and one number.
- type: Read-Only Property.
- return type: Bool
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
// useful for passwords
"123abc".isAlphaNumeric -> true
"abc".isAlphaNumeric -> false
--
Check if string is valid email format.
- type: Read-Only Property.
- return type: Bool
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"[email protected]".isEmail -> true
--
Check if string is a valid URL.
- type: Read-Only Property.
- return type: Bool
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"https://google.com".isValidUrl -> true
--
Check if string is a valid https URL.
- type: Read-Only Property.
- return type: Bool
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"https://google.com".isValidHttpsUrl -> true
--
Check if string is a valid http URL.
- type: Read-Only Property.
- return type: Bool
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"http://google.com".isValidHttpUrl -> true
--
Check if string is a valid schemed URL.
- type: Read-Only Property.
- return type: Bool
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"https://google.com".isValidSchemedUrl -> true
"google.com".isValidSchemedUrl -> false
--
Check if string contains only numbers.
- type: Read-Only Property.
- return type: Bool
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"123".isNumeric -> true
"abc".isNumeric -> false
--
Last character of string (if applicable).
- type: Read-Only Property.
- return type: String?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hello".lastCharacter -> Optional("o")
--
Latinized string.
- type: Read-Only Property.
- return type: String
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hèllö Wórld!".latinized -> "Hello World!"
--
Array of strings separated by new lines.
- type: Read-Only Property
- return type: Int
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hello world!".length -> 12
--
Array of strings separated by new lines.
- type: Read-Only Property
- return type: [String]
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hello\ntest".lines -> ["Hello", "test"]
--
The most common character in string.
- type: Read-Only Property.
- return type: String
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"This is a test, since e is appearing everywhere e should be the common character".mostCommonCharacter -> "e"
--
Reversed string.
- type: Read-Only Property.
- return type: String
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Swift".reversed -> "tfiwS"
--
Bool value from string (if applicable).
- type: Read-Only Property.
- return type: Bool?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"1".bool -> true
"False".bool -> false
"Hello".bool = nil
--
Date object from "yyyy-MM-dd" formatted string
- type: Read-Only Property.
- return type: Date?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"2007-06-29".date -> Date?
--
Date object from "yyyy-MM-dd HH:mm:ss" formatted string.
- type: Read-Only Property.
- return type: Date?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"2007-06-29 14:23:09".dateTime -> Date?
--
Double value from string (if applicable).
- type: Read-Only Property.
- return type: Double?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"20".double -> 20.0
--
Float value from string (if applicable).
- type: Read-Only Property.
- return type: Float?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"21".float -> 21.0
--
Float32 value from string (if applicable).
- type: Read-Only Property.
- return type: Float32?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"21.86".float32 -> 21.86
--
Float64 value from string (if applicable).
- type: Read-Only Property.
- return type: Float64?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"23.45".float64 -> 23.45
--
Integer value from string (if applicable).
- type: Read-Only Property.
- return type: Int?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"101".int -> 101
--
Int16 value from string (if applicable).
- type: Read-Only Property.
- return type: Int16?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"101".int16 -> 101
--
Int32 value from string (if applicable).
- type: Read-Only Property.
- return type: Int32?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"101".int32 -> 101
--
Int64 value from string (if applicable).
- type: Read-Only Property.
- return type: Int64?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"101".int64 -> 101
--
Int8 value from string (if applicable).
- type: Read-Only Property.
- return type: Int8?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"101".int8 -> 101
--
URL from string (if applicable).
- type: Read-Only Property.
- return type: URL?
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"https://google.com".url -> URL(string: "https://google.com")
"not url".url -> nil
--
String with no spaces or new lines in beginning and end.
- type: Read-Only Property.
- return type: String
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
" hello \n".trimmed -> "hello"
--
Array with unicodes for all characters in a string.
- type: Read-Only Property.
- return type: [Int]
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"SwifterSwift".unicodeArray -> [83, 119, 105, 102, 116, 101, 114, 83, 119, 105, 102, 116]
--
Readable string from a URL string.
- type: Read-Only Property.
- return type: String
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"it's%20easy%20to%20decode%20strings".urlDecoded -> "it's easy to decode strings"
--
URL escaped string.
- type: Read-Only Property.
- return type: String
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"it's easy to encode strings".urlEncoded -> "it's%20easy%20to%20encode%20strings"
--
String without spaces and new lines.
- type: Read-Only Property.
- return type: String
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
" \n Swifter \n Swift ".withoutSpacesAndNewLines -> "SwifterSwift"
--
Safely subscript string with index.
- type: Method.
- return type: String?
- parameters:
- i: index.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hello World!"[3] -> "l"
"Hello World!"[20] -> nil
--
Safely subscript string within a half-open range.
- type: Method.
- return type: String?
- parameters:
- range: Half-open range.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hello World!"[6..<11] -> "World"
"Hello World!"[21..<110] -> nil
--
Safely subscript string within a closed range.
- type: Method.
- return type: String?
- parameters:
- range: Closed range.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hello World!"[6...11] -> "World!"
"Hello World!"[21...110] -> nil
--
Copy string to global pasteboard.
- type: Method.
- availability:
iOS 8+
macOS 10.10+
.
Example
"SomeText".copyToPasteboard() // copies "SomeText" to pasteboard
--
Converts string format to CamelCase.
- type: Mutating Method.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
var str = "sOme vaRiabLe Name"
str.camelize()
print(str) // prints "someVariableName"
--
Check if string contains one or more instance of substring.
- type: Method.
- return type: Bool
- parameters:
- string: substring to search for.
- caseSensitive: set true for case sensitive search (default is true).
- returns: true if string contains one or more instance of substring.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hello World!".contain("O") -> false
"Hello World!".contain("o", caseSensitive: false) -> true
--
Count of substring in string.
- type: Method.
- return type: Int
- parameters:
- string: substring to search for.
- caseSensitive: set true for case sensitive search (default is true).
- returns: count of appearance of substring in string.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hello World!".count(of: "o") -> 2
"Hello World!".count(of: "L", caseSensitive: false) -> 3
--
Check if string ends with substring.
- type: Method.
- return type: Bool
- parameters:
- string: substring to search if string ends with.
- caseSensitive: set true for case sensitive search (default is true).
- returns: true if string ends with substring.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hello World!".end(with: "!") -> true
"Hello World!".end(with: "WoRld!", caseSensitive: false) -> true
--
First index of substring in string.
- type: Method.
- return type: Int?
- parameters:
- string: substring to search for.
- returns: first index of substring in string (if applicable).
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hello World!".firstIndex(of: "l") -> 2
"Hello World!".firstIndex(of: "s") -> nil
--
Latinize string.
- type: Mutating Method.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
var str = "Hèllö Wórld!"
str.latinize()
print(str) // prints "Hello World!"
--
Random string of given length.
- type: Static Method.
- return type: String
- parameters:
- ofLength: number of characters in string.
- returns: random string of given length.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
String.random(ofLength: 18) -> "u7MMZYvGo9obcOcPj8"
--
String by replacing part of string with another string.
- type: Method.
- return type: String
- parameters:
- substring: old substring to find and replace.
- newString: new string to insert in old string place.
- returns: string after replacing substring with newString.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"#number# items".replacing("#number#", with: "10") -> "10 items"
--
Reverse string.
- type: Mutating Method.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
var str = "Hello World!"
str.reverse()
print(str) // prints "!dlroW olleH"
--
Sliced string from a start index with length.
- type: Method.
- return type: String?
- parameters:
- i: string index the slicing should start from.
- length: amount of characters to be sliced after given index.
- returns: sliced substring of length number of characters (if applicable).
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hello World".slicing(from: 6, length: 5) -> "World"
--
Slice given string from a start index with length (if applicable).
- type: Mutating Method.
- parameters:
- i: string index the slicing should start from.
- length: amount of characters to be sliced after given index.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
var str = "Hello World"
str.slice(from: 6, length: 5)
print(str) // prints "World"
--
Sliced string from a start index to an end index.
- type: Method.
- return type: String?
- parameters:
- start: string index the slicing should start from.
- end: string index the slicing should end at.
- returns: sliced substring starting from start index, and ends at end index (if applicable).
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hello World".slicing(from: 6, to: 11) -> "World"
--
Slice given string from a start index to an end index (if applicable).
- type: Mutating Method.
- parameters:
- start: string index the slicing should start from.
- end: string index the slicing should end at.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
var str = "Hello World"
str.slice(from: 6, to: 11)
print(str) // prints "World"
--
Sliced string from a start index.
- type: Method.
- return type: String?
- parameters:
- i: string index the slicing should start from.
- returns: substring starting from start index (if applicable).
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"Hello World".slicing(at: 6) -> "World"
--
Slice given string from a start index (if applicable).
- type: Mutating Method.
- parameters:
- i: string index the slicing should start from.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
var str = "Hello World"
str.slice(at: 6)
print(str) // prints "World"
--
Array of strings separated by given string.
- type: Method.
- return type: [String]
- parameters:
- separator: separator to split string by.
- returns: array of strings separated by given string.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"hello World".splited(by: " ") -> ["hello", "World"]
--
Check if string starts with substring.
- type: Method.
- return type: Bool
- parameters:
- suffix: substring to search if string starts with.
- caseSensitive: set true for case sensitive search (default is true).
- returns: true if string starts with substring.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"hello World".start(with: "h")
"hello World".start(with: "H", caseSensitive: false)
--
Date object from string of date format.
- type: Method.
- return type: Date?
- parameters:
- format: date format.
- returns: Date object from string (if applicable).
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"2017-01-15".date(withFormat: "yyyy-MM-dd") -> Date set to Jan 15, 2017
"not date string".date(withFormat: "yyyy-MM-dd") -> nil
--
Removes spaces and new lines in beginning and end of string.
- type: Mutating Method.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
var str = " \n Hello World \n\n\n"
str.trim()
print(str) // prints "Hello World"
--
Truncate string (cut it to a given number of characters).
- type: Mutating Method.
- parameters:
- toLength: maximum number of characters before cutting.
- trailing: string to add at the end of truncated string (default is "...").
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
var str = "This is a very long sentence"
str.truncate(toLength: 14)
print(str) // prints "This is a very..."
--
Truncated string (limited to a given number of characters).
- type: Method.
- return type: String
- parameters:
- toLength: maximum number of characters before cutting.
- trailing: string to add at the end of truncated string.
- returns: truncated string.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
"This is a very long sentence".truncated(toLength: 14) -> "This is a very..."
"Short sentence".truncated(toLength: 14) -> "Short sentence"
--
Convert URL string to readable string.
- type: Mutating Method.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
var str = "it's%20easy%20to%20decode%20strings"
str.urlDecode()
print(str) // prints "it's easy to decode strings"
--
Escape string.
- type: Mutating Method.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
var str = "it's easy to encode strings"
str.urlEncode()
print(str) // prints "it's%20easy%20to%20encode%20strings"
--
Repeat string multiple times.
- type: Infix Operator.
- return type: String
- returns: new string with given string repeated n times.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
'bla' * 3 -> "blablabla"
--
Create a new random string of given length.
- type: Initializer.
- return type: String
- parameters:
- length: number of characters in string.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
String(randomOfLength: 10) -> "gY8r3MHvlQ"
--
Create a new string from a base64 string (if applicable).
- type: Optional Initializer.
- return type: String?
- parameters:
- base64: base64 string.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
String(base64: "SGVsbG8gV29ybGQh") = "Hello World!"
String(base64: "hello") = nil
--
NSString from a string.
- type: Read-Only Property.
- return type: NSString
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
--
NSString lastPathComponent.
- type: Read-Only Property.
- return type: String
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
--
NSString pathExtension.
- type: Read-Only Property.
- return type: String
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
--
NSString deletingLastPathComponent.
- type: Read-Only Property.
- return type: String
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
--
NSString deletingPathExtension.
- type: Read-Only Property.
- return type: String
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
--
NSString pathComponents.
- type: Read-Only Property.
- return type: [String]
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
--
NSString appendingPathComponent(str: String)
- type: Method.
- return type: String
- parameters:
- str: the path component to append to the receiver.
- returns: a new string made by appending aString to the receiver, preceded if necessary by a path separator.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
--
NSString appendingPathExtension(str: String).
- type: Method.
- return type: String
- parameters:
- str: The extension to append to the receiver.
- returns: a new string made by appending to the receiver an extension separator followed by ext (if applicable).
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
--